如何让 Tampermoney 为访问过的链接着色?

问题描述 投票:0回答:1

HackerNews (https://news.ycombinator.com/) 将访问过的链接设置为与未访问过的链接颜色相似的颜色。我想将访问的链接设置为对比色。

我是 Tampermonkey(以及一般的 web/js)新手。我进行了搜索,发现最接近的是我修改过的这段代码。遗憾的是,它似乎对访问链接的颜色没有任何影响。

// ==UserScript==
// @name          Hacker News Visited Link Highlighter
// @description   Highlights visited links on Hacker News with a different color
// @namespace     http://tampermonkey.net/
// @match         https://news.ycombinator.com/*
// @version       2024-01-13
// ==/UserScript==
// History:
// --------
// 2024-01-13  First version

(function () {

   GM_addStyle("a:visited { color: #FF0084 }");

})();
greasemonkey tampermonkey visited
1个回答
0
投票

您可以将行

@grant GM_addStyle
添加到您的用户脚本标题中,如下所示:

// ==UserScript==
// @name          Hacker News Visited Link Highlighter
// @description   Highlights visited links on Hacker News with a different color
// @namespace     http://tampermonkey.net/
// @match         https://news.ycombinator.com/*
// @version       2024-01-13
// @grant         GM_addStyle
// ==/UserScript==

或者您也可以自己注入所需的 HTML,如下所示:

// ==UserScript==
// @name          Hacker News Visited Link Highlighter
// @description   Highlights visited links on Hacker News with a different color
// @namespace     http://tampermonkey.net/
// @match         https://news.ycombinator.com/*
// @version       2024-01-13
// ==/UserScript==

(function() {
    'use strict';
    document.querySelector('body').insertAdjacentHTML('beforeend', init_css() );

    function init_css(){
        return `
        <style id="myInitCss">
            a:visited { color: #FF0084; }
        </style>
        `;
    }
})();

使用第二种方法还演示了如何向网页添加新的 DIV、按钮等内容。

© www.soinside.com 2019 - 2024. All rights reserved.