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();
})()
