作为推出新的网络站点主题的一部分,我经常访问的许多Stack站点现在都有文章中的链接和强调的评论。
我更喜欢不带下划线的外观,而且由于我主要使用Chrome (68.0.3440.106 (正式构建)(64位))和Edge (42.17692.1004.0),它们似乎没有全局覆盖设置,所以我安装了坦帕猴并编写了一个基于我在Stack应用程序上找到的一个例子的小用户脚本,以及通过搜索这个站点寻找解决方案找到的一些相关代码:
// ==UserScript==
// @name Remove link underlines on Stack Exchange
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match *://*.stackexchange.com/*
// @match *://*.stackoverflow.com/*
// @match *://*.mathoverflow.com/*
// @match *://*.serverfault.com/*
// @match *://*.superuser.com/*
// @match *://*.stackapps.com/*
// @match *://*.askubuntu.com/*
// @grant none
// @run-at document-body
// ==/UserScript==
(function() {
'use strict';
// Your code here...
var style = document.createElement("style");
style.appendChild(document.createTextNode("a {text-decoration: none !important;}"));
document.head.appendChild(style);
})();这似乎基本上是很好的工作,虽然我确实注意到简短的链接下划线,有时在页面加载之前,它被替换为无下划线外观。
,我能做些什么,使我喜欢的外观看起来更立即,而不需要短暂的下划线吗?
我尝试了// @run-at document-start,它删除了闪烁,但有时它根本无法应用样式更改。
我没有这方面的经验,除了黑客第一个用户脚本,所以请解释任何修改的好处和风险。
为了与我选择的浏览器兼容,我选择了(并加上标签)Tamper猴子,并使我能够在将来运行其他用户脚本(包括不限于样式更改的脚本)。
发布于 2018-08-19 19:09:26
参见:如何用Greasemonkey/Tampermonkey脚本更改类CSS?
对于纯CSS/样式的更改,https://add0n.com/stylus.html是一个更好的匹配,并且通常优于Tamper猴子。
无论如何,为了避免/减少@run-at document-start**.** you do 需要,否则,页面将在添加样式之前基本呈现。
但是,如果这偶尔不能工作,则很可能在这些实例中的document.head可用之前,它就会触发。(理想情况下,会在浏览器控制台上看到一个错误。)
页面CSS (或其他扩展)使用!important;或通过链接的style属性应用CSS的可能性也很小。如果脚本失败,请检查页面源(以及前面提到的浏览器控制台)。
无论如何,按照链接的答案注入CSS --并消除不必要的cruft -您的脚本变成:
// ==UserScript==
// @name Stack Exchange, Remove link underlines
// @version 0.2
// @match *://*.stackexchange.com/*
// @match *://*.stackoverflow.com/*
// @match *://*.mathoverflow.com/*
// @match *://*.serverfault.com/*
// @match *://*.superuser.com/*
// @match *://*.stackapps.com/*
// @match *://*.askubuntu.com/*
// @grant GM_addStyle
// @run-at document-start
// ==/UserScript==
GM_addStyle ( `a {text-decoration: none !important;}` );或者,如果您被诅咒需要支持Greasemonkey 4+:
// ==UserScript==
// @name Stack Exchange, Remove link underlines
// @version 0.2
// @match *://*.stackexchange.com/*
// @match *://*.stackoverflow.com/*
// @match *://*.mathoverflow.com/*
// @match *://*.serverfault.com/*
// @match *://*.superuser.com/*
// @match *://*.stackapps.com/*
// @match *://*.askubuntu.com/*
// @grant none
// @run-at document-start
// ==/UserScript==
var D = document;
var newNode = D.createElement ('style');
newNode.textContent = "a {text-decoration: none !important;}";
var targ = D.getElementsByTagName ('head')[0] || D.body || D.documentElement;
targ.appendChild (newNode);https://stackoverflow.com/questions/51918513
复制相似问题