/*
    Rewrites Google Image urls to link directly to the image.

    Based off of Patrick Cavit's greasemonkey plugin

    - Chris Becker 
    http://www.csh.rit.edu/~topher/gm
*/

// ==UserScript==
// @name          Google Image Relinker (for Turnabout)
// @namespace     
// @description	  Rewrites Google Image Search links to point straight to the pictures
// @include       http://images.google.*/*
// ==/UserScript==


var link;

/* loop over all the a tags */
var links = document.getElementsByTagName("a"); 
for(i=0; i < links.length; i++) {
        var href = new String( links[i].getAttribute("href") );
        /* extract day and month */
	var start = href.indexOf('imgurl=');
	var end = href.indexOf('&imgrefurl=');
        if( start != -1 && end != -1) {
              links[i].setAttribute("href",href.substring(start+7,end));
        }
}
