// ==UserScript==
// @name Links2Images
// @author Tomasz Wójcikowski
// @description  Replaces links to images with the actual images.
// @ujs:category general: enhancements
// @ujs:published 2005-05-28 12:47
// @ujs:modified 2005-09-19 09:19
// @ujs:documentation http://userjs.org/scripts/general/enhancements/links-2-images 
// @ujs:download http://userjs.org/scripts/download/general/enhancements/links-2-images.user.js 
// @ujs:download.gm http://userjs.org/scripts/download/general/enhancements/links-2-images.user.js
// ==/UserScript==

/* 
 * Copyright © 2005 by Tomasz Wójcikowski
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 */


(function () {
	var links = document.getElementsByTagName ("a");
	for (var i = links.length - 1; i >= 0; i--) {
		// search for all links with href to image file
		if (links[i].href && links[i].href.match(/^.*\.(jpe?g|png|bmp|gif)$/i)) {
			// convert <a> into <img>, and href into src 
			var img = document.createElement("img") ;
			img.setAttribute ("src", links[i].href) ;
			img.setAttribute ("class", "image-link") ;
			img.setAttribute ("alt", links[i].getAttribute('title')) ;
			links[i].parentNode.replaceChild (img, links[i]) ;
		}
	}
})();