-1

I grabbed a few small scripts and threw them together to take google's new image layout and turn back into the old one, then take the images and replace them with the full size versions. Worked great until about last week. Not sure what changed on the server side.

(function() {

    // Get list of all anchor tags that have an href attribute containing the start and stop key strings.
    var fullImgUrls = selectNodes(document, document.body, "//a[contains(@href,'/imgres?imgurl\x3d')][contains(@href,'\x26imgrefurl=')]");

    //clear existing markup
    var imgContent = document.getElementById('ImgContent');
    imgContent.innerHTML = "";

    for(var x=1; x<=fullImgUrls.length; x++) {
        //reverse X to show images in correct order using .insertBefore imgContent.nextSibling
        var reversedX = (fullImgUrls.length) - x;
        // get url using regexp
        var fullUrl = fullImgUrls[reversedX].href.match( /\/imgres\?imgurl\=(.*?)\&imgrefurl\=(.*?)\&usg/ );
        // if url was fetched, create img with fullUrl src
        if(fullUrl) {
            newLink = document.createElement('a');
            imgContent.parentNode.insertBefore(newLink , imgContent.nextSibling);
            newLink.href = unescape(fullUrl[2]);
            newElement = document.createElement('img');
            newLink.appendChild(newElement);
            newElement.src = decodeURI(fullUrl[1]);
            newElement.border = 0;
            newElement.title = fullUrl[2];
        }
    }

    function selectNodes(document, context, xpath) {
        var nodes = document.evaluate(xpath, context, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
        var result = [];
        for (var x=0; x<nodes.snapshotLength; x++) {
            result.push(nodes.snapshotItem(x));
        }
        return result;
    }
})();
  • check your browser javascript console (FF and Chrome have it) – Marek Sebera Oct 02 '11 at 16:14
  • Uncaught TypeError: Cannot set property 'innerHTML' of null The error is occurring, not sure which null, and not sure why it worked before and suddenly no longer works. Tried changing the namespaceResolver parameter of the document.evaluate but I've had no luck in solving the underlying issue. – Bobby Martin Oct 09 '11 at 23:27
  • There must not be an `ImgContent` element any more. –  Oct 09 '11 at 23:56
  • That would make sense. Thanks for the idea, I'm gonna go mess with it! – Bobby Martin Oct 10 '11 at 00:01
  • Looks like you might want to iterate over the items in the `rg_ul` list to do what you're doing. –  Oct 10 '11 at 00:05
  • It's not really my code, and while I understand basically how it works, I'm not intimately familiar with google's image search code. I just took to scripts and put them together to make mine and several other users' life a little more convenient. – Bobby Martin Oct 10 '11 at 00:29

2 Answers2

0

Google changed the 'ImgContent' id for the image table holder to something slightly more obscure. A quick change had everything working again. I made a simple problem complicated by looking past the easy stuff. Thanks to darvids0n for the enabling, he ultimately pointed out what I was missing.

  • Well done. Mark your answer as correct. And if you're making the finished, corrected code available to the general public, let us know where you posted it. – james.garriss Oct 10 '11 at 14:15
0

the script is not going to work as said by bobby .

try this grease monkey script from user script repository.

rip Google image search :- http://userscripts.org/scripts/show/111342

vinrav
  • 371
  • 3
  • 12