自动给 Google 搜索结果添加查看缓存功能

作者:matrix 被围观: 334 次 发布时间:2024-07-12 分类:零零星星 | 3 条评论 »

google 搜索结果的查看缓存功能下线其实很久了,每次都得手动 `cache:https://www.hhtjim.com/` 就很麻烦。

有空搞了个油猴脚本能自动在Google搜索结果中添加 [Cache] 链接到该网页的缓存版本 🥳🥳 这就方便多了

安装地址

https://greasyfork.org/zh-CN/scripts/500422-google-cache-viewer

脚本代码

// ==UserScript==
// @name         Google cache viewer
// @namespace    http://hhtjim.com/
// @version      1.0.1
// @description  Automatically adds a cache link to Google Search results. / Google搜索结果中添加缓存按钮
// @author       Hootrix
// @include      https://www.google.tld/search?*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    window.addEventListener('load', function() {
        // select containers `cite[role="text"]`
        const containers = document.querySelectorAll('.g.Ww4FFb.vt6azd.tF2Cxc.asEBEc');

        containers.forEach(container => {
            //const cite = container.querySelector('cite[role="text"]');
            let cites = container.querySelectorAll('cite[role="text"]');
            // last item
            let cite = cites[cites.length - 1];
            const link = container.querySelector('a[data-ved]');
            if (cite && cite.textContent.startsWith('http')) {
                //const url = cite.textContent;
                const url = link.href
                const cacheUrl = `https://webcache.googleusercontent.com/search?q=cache:${url}`;

                const cacheDiv = document.createElement('div');
                cacheDiv.className = '';  // class name  eFM0qc
                cacheDiv.innerHTML = `<a href="${cacheUrl}" target="_blank" style="visibility:visible;color: blue; margin-left: 10px;" rel="noopener">[Cache]</a>`;

                if (cite.parentElement) {
                    cite.parentElement.appendChild(cacheDiv);
                }
            }
        });
    });
})();
其他文章:
本文固定链接:https://www.hhtjim.com/google-cache-viewer.html
matrix
本文章由 matrix 于2024年07月12日发布在零零星星分类下,目前没有通告,你可以至底部留下评论。
转载请注明:自动给 Google 搜索结果添加查看缓存功能-HHTjim'S 部落格
关键字:,

有3 条评论 »

  1. 电商梦里 电商梦里 2024-8-8 10:40:16 +0800#2

    感谢分享

  2. Ryan Ryan 2024-7-26 10:16:32 +0800#1

    才知道谷歌的缓存功能还能用

    • matrix matrix 2024-8-6 15:20:24 +0800

      是的 大多数还是可以看到缓存页面

添加新评论 »

 🙈 😱 😂 😛 😭 😳 😀 😆 👿 😉 😯 😮 😕 😎 😐 😥 😡 😈 💡

插入图片

NOTICE: You should type some Chinese word (like “你好”) in your comment to pass the spam-check, thanks for your patience!