Google Images direct links

By Dwoo Last update Oct 26, 2009 — Installed 3,744 times. Daily Installs: 4, 9, 205, 190, 106, 28, 22, 26, 15, 22, 21, 22, 18, 11, 13, 115, 13, 18, 21, 5, 11, 20, 12, 9, 7, 23, 19, 16, 16, 22, 17, 11

There are 6 previous versions of this script.

// ==UserScript==
// @name           Google Images direct links
// @author         Dwoo
// @version        2009-10-26
// @namespace      http://userscripts.org/scripts/show/48293
// @description    Makes images link directly to the original in Google Images search. The source website link is moved to the green URL below the image.
// @include        http://images.google.tld/*
// @include        http://www.google.tld/images?*
// ==/UserScript==

(function () {

function evalNodes(path) {
	return document.evaluate(path, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
}

var cont = evalNodes('//div[starts-with(@id, "ImgCont")]').snapshotItem(0);

function addLinks() {
	var imgs = evalNodes('//a[contains(@href, "imgurl")]');
	var links = evalNodes('//td[starts-with(@id, "tDataText")]//div[@class="a"]');
	var image, link, urls, a;
	for (var i = 0; image = imgs.snapshotItem(i), link = links.snapshotItem(i);  i++) {
		urls = image.href.match(/imgurl=(.*)&imgrefurl=(.*)&usg/);
		image.href = decodeURIComponent(urls[1]);
		a = document.createElement('a');
		a.innerHTML = link.innerHTML;
		a.setAttribute('class', "a");
		a.setAttribute('style', "border-style: none");
		a.setAttribute('href', decodeURIComponent(urls[2]));
		link.parentNode.replaceChild(a, link);
	}
	if (cont) {
		cont.addEventListener('DOMNodeInserted', trigger, false);
	}
}

function trigger() {
	cont.removeEventListener('DOMNodeInserted', trigger, false);
	setTimeout(addLinks, 100);
}

addLinks();
})()