Google Images NoFrame link

By m4n_in_bl4ck Last update Dec 28, 2007 — Installed 1,791 times. Daily Installs: 1, 0, 4, 2, 6, 4, 0, 3, 1, 3, 1, 2, 1, 4, 2, 1, 1, 1, 2, 1, 0, 5, 2, 3, 2, 3, 0, 3, 3, 9, 4, 0
// ==UserScript==
// @name           Google Images NoFrame link
// @author         Ricardo Ferreira
// @namespace      m4n_in_bl4ck
// @description    Adds a noframe link to images in Google Images search results
// @include        http://images.google.*/*
// ==/UserScript==
// Version	   1.0
// Credits	   Thanks to Trixie

(function() 
{
	function GetImageUrl(theUrl)
	{
		if (theUrl == null)
			return(false);

		// Looking for "imgurl=..."
		var searchStr = "imgurl=";
		var pos = theUrl.indexOf(searchStr);
		var temp = null;

		if (pos >= 0)
		{
			var pos1 = theUrl.indexOf("&");
	    		temp = theUrl.substring(pos + searchStr.length, pos1);
		}
		
		return temp;
	}
	
	function MakeNoFrameLink(url)
	{
	    if (url != null && url.length > 0)
	    {
			var container = document.createElement("span");
			container.appendChild(document.createTextNode(" "));
			
			var newLink = document.createElement("a");
			newLink.setAttribute("href", url);
			newLink.appendChild(document.createTextNode(">>"));
			container.appendChild(newLink);
			
			return container;
	    }
	    
	    return null;
	}

	var hyperlinks = document.getElementsByTagName("a");

	for (var i = 0; i < hyperlinks.length; ++i)
	{
		var node = hyperlinks[i];
		var href = node.getAttribute("href");

		var imgUrl = GetImageUrl(href);
		if (imgUrl != null)
		{
		    var link = MakeNoFrameLink(imgUrl);
		    
		    if (link != null)
		    {
				if (node.nextSibling == null)
					node.parentNode.appendChild(link);
				else
					node.parentNode.insertBefore(link, node.nextSibling);
		    }
		}
	}
})();