用于谷歌图像翻录的 JavaScript 因更新而中断

发布于 2024-12-07 12:48:15 字数 1689 浏览 1 评论 0原文

我抓起一些小脚本并将它们放在一起,以采用谷歌的新图像布局并返回到旧的图像布局,然后获取图像并将其替换为全尺寸版本。直到上周为止一直工作得很好。不确定服务器端发生了什么变化。

(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;
    }
})();

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;
    }
})();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

泪眸﹌ 2024-12-14 12:48:15

Google 将图像表持有者的“ImgContent”id 更改为稍微晦涩的内容。快速的改变让一切都恢复了正常。我把一个简单的问题复杂化了,忽略了简单的事情。感谢 darvids0n 的支持,他最终指出了我所遗漏的内容。

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.

九歌凝 2024-12-14 12:48:15

该脚本不会像鲍比所说的那样运行。

尝试用户脚本存储库中的这个油脂猴脚本。

放弃 Google 图片搜索:- http://userscripts.org/scripts/show/111342

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文