Source for "Google Image Relinker Mod"

By thorbenhauer
Has 43 other scripts.


// Google Image Relinker Mod user script
// version 0.3
// 2008-07-10
// Copyright 2006-2008, thorbenhauer
// Released under the GPL license
// http://www.gnu.org/copyleft/gpl.html
//
// -----------------------------------------------------------------------------
//
// Based on Google Image Relinker user script by Patrick Cavit
// http://userscripts.org/users/187
// Script location: http://userscripts.org/scripts/show/792 
//
// Copyright Notice by Patrick Cavit, pcavit@gmail.com:
// Copy, use, modify, spread as you see fit. Massive thanks go out to
// Eric Hamiter, this code is just a quick modification of his extension at
// http://roachfiend.com/
//
// With Modifications inspired by
// FurYy http://userscripts.org/people/1618
// Juhani Naskali http://userscripts.org/people/8345
// ekbworldwide http://userscripts.org/users/39581
//
// -----------------------------------------------------------------------------
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//
// -----------------------------------------------------------------------------
//
// ==UserScript==
// @name          Google Image Relinker Mod
// @namespace     http://userscripts.org/users/9022
// @description   http://userscripts.org/scripts/show/5059
// @include       http://images.google.tld/images?*
//                for Opera (which doesn't understand tld):
// @include       http://images.google.com/images?*
// @include       http://images.google.de/images?*
// ==/UserScript==
//
// -----------------------------------------------------------------------------
(function () { // function wrapper for Opera

createLinks();
window.addEventListener("resize", createLinks, true);

function createLinks() {
    var googLinks = document.evaluate('//td/a[contains(@href, ' +
        '"/imgres?imgurl=")][contains(@href, "&imgrefurl=")]', document, null,
        XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
    var googFonts = document.evaluate('//font[contains(@color, "#008000")]',
        document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
    var link, gmatch, font, newLink, decodedLink;       
    for (var i = 0; i < googLinks.snapshotLength; i++) {
        link = googLinks.snapshotItem(i);
        font = googFonts.snapshotItem(i);
        gmatch = link.href.match(/\&imgrefurl\=(.*?)(\&start\=|\&h\=)/ );
        font.innerHTML = "<a href=\"" + decodeURIComponent(gmatch[1]) + "\">" +
            font.innerHTML + "</a>";
        if (font.parentNode.getAttribute("framedView") == null) {
            font.parentNode.appendChild(document.createElement("br"));
            newLink = document.createElement("a");
            newLink.setAttribute("style", "font-size: x-small");
            font.parentNode.setAttribute("framedView", "set");
            newLink.href = link.href;
            newLink.innerHTML = "Framed View";
            font.parentNode.appendChild(newLink);
        }
        gmatch = link.href.match(/\/imgres\?imgurl\=(.*?)\&imgrefurl\=/);
        decodedLink = decodeURI(gmatch[1]);
        /* blogger.com content-disposition HTTP response header workaround
           toggle comment on next line to enable/disable */
        //if (decodedLink.search(/^http:\/\/bp\d\.blogger\.com\//) < 0)
            link.href = decodedLink;
    }
}

})(); // function wrapper for Opera