Magnus2 / Google Images Relinker 2

// ==UserScript==
// @name        Google Images Relinker 2
// @namespace   own
// @include     https://www.google.de/search*tbm=isch*
// @include     https://www.google.com/search*tbm=isch*
// @include     https://encrypted.google.com/search*tbm=isch*
// @version     1
// @grant       none
// ==/UserScript==

function Relink()
{
	// divs that contain thumbnail and url
	var divs = document.getElementsByClassName("rg_di rg_bx rg_el ivg-i")

	for(var i = 0; i < divs.length; ++i)
	{
		var div = divs.item(i)
		
		// skip already relinked thumbnails
		var doneAttr = div.getAttributeNode("id");
		var done = doneAttr != null && doneAttr.value == "1"
		if (done) continue
		
		// remove interfering js calls
		var aElem = div.firstChild
		aElem.removeAttribute("jsaction")
		
		// url to actual image is part of json string
		var subDiv = div.childNodes[1]
		var json = JSON.parse(subDiv.innerHTML)
		var url = json.ou
		
		// relink
		aElem.setAttribute("href", url)
		
		// mark as relinked
		var doneAttr_ = document.createAttribute("id")
		doneAttr_.value = "1"
		div.setAttributeNode(doneAttr_)
	}
}

// relink once all loaded thumbnails
Relink()

// relink again after scrolling has triggered dynamic loading of more thumbnails
var scrollCounter = 0
function Scrolled()
{
	++scrollCounter
	if(scrollCounter == 10)
	{
		scrollCounter = 0
		Relink()
	}
}

window.addEventListener("scroll", Scrolled, false);