gpt4 book ai didi

CSS 背景颜色未一致地应用于已访问的链接。 GM_addStyle 添加的 CSS

转载 作者:行者123 更新时间:2023-11-28 09:38:00 24 4
gpt4 key购买 nike

我注意到 GM_addStyle() 添加的 CSS 有一些奇怪的行为。我有以下用户脚本:

// ==UserScript==
// @name Reddit
// @namespace http://example.com
// @include http://www.reddit.com/
// @grant GM_addStyle
// @version 1
// ==/UserScript==

GM_addStyle("a:visited { background-color: yellow !important; }");

现在,我希望该行为适用于所有链接或不适用任何链接(由于安全补丁),但我得到的是不一致的行为,因为它适用于某些链接,但不适用于其他链接。

Works for hot/top/wiki, but not any other links

谁能为我解释一下上述行为?

最佳答案

来自 Privacy and the :visited selector at MDN :

Only the following properties can be applied to visited links:

  • color
  • background-color
  • border-color (and its sub-properties)
  • outline-color
  • The color parts of the fill and stroke properties

In addition, even for the properties you can set for visited links, you won't be able to change the transparency between unvisited and visited links, as you otherwise would be able to using rgba() or hsla() color values or the transparent keyword.

显然,这意味着,在 Firefox 中,为了让您更改背景颜色,链接必须首先具有背景(您不能使用 :visited 添加背景 选择器)。因此,在尝试设置已访问链接的背景颜色样式之前设置背景。

这对我有用:

// ==UserScript==
// @name _Reddit, style visited links
// @include http://www.reddit.com/*
// @grant GM_addStyle
// @version 1
// ==/UserScript==

GM_addStyle (
/* For precision, only prime the desired links, that don't
otherwise have a BG.
*/
"a.title { background: white; }"
+ "a:visited { background-color: yellow !important; }"
);


请注意,我只是“启动”了我明确感兴趣的链接,这些链接还没有背景。因此 a.title {... 而不是 a {...


另请注意,对于仅更改样式,Stylish通常是更好的选择(性能和易于设置)。

关于CSS 背景颜色未一致地应用于已访问的链接。 GM_addStyle 添加的 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17764376/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com