Image Expander

By Joel Lee Last update Feb 18, 2010 — Installed 709 times. Daily Installs: 10, 5, 18, 3, 2, 4, 5, 0, 5, 1, 3, 4, 1, 2, 0, 3, 1, 3, 1, 1, 0, 1, 0, 1, 0, 0, 2, 0, 0, 3, 3

There are 3 previous versions of this script.

// ==UserScript==
// @name           Image Expander
// @namespace      http://blog.bcse.info/image-expander
// @description    Expand *.jpg, *.jpeg, *.png and *.gif
// @version        0.3.3
// @include        *
// ==/UserScript==

var imgLinks = document.querySelectorAll("a[href$=jpg]>img:only-child,a[href$=jpeg]>img:only-child,a[href$=png]>img:only-child,a[href$=gif]>img:only-child");
for (var i = 0; i < imgLinks.length; i++) {
	var thisLink = imgLinks[i].parentNode;
	if (thisLink.childNodes.length == 1) { // :only-child pseudo-class does not count text nodes as a child
		var imageUri = thisLink.getAttribute('href');
		(function(imageUri, thisLink){
			var img = document.createElement('img');
			img.addEventListener('load', function(){thisLink.parentNode.replaceChild(img, thisLink)}, false);
			img.setAttribute('src', imageUri);
		})(imageUri, thisLink);
	}
}