我正在尝试创建一个用户样式(作为用户脚本安装在 Google Chrome 中)。 这只是一些 CSS 来隐藏页面上的所有内容,只显示 an image .
html { height:100%;
background:url(/image/1xZIO.png) no-repeat center fixed #FFFFFF !important;
overflow:hidden;
}
*:not(html) { display:none; }
我想说我对 CSS 的理解有问题,但这在 Mozilla Firefox 中有效(将此代码粘贴到 userContent.css强>并且它的行为符合预期)。
也尝试过body
而不是html
, visibility:collapse;
而不是display:none;
更具体:not
选择器。
这里是how userstyles.org makes this CSS into a userscript
请解释一下这是怎么回事!非常感谢!
最佳答案
以下代码在我的 chrome 上运行良好。我删除了您的 @namespace 行并在 html 元素上应用了样式。
// @description Block entire websites in style!
// @author monn43
// @homepage http://userstyles.org/styles/53487
// @run-at document-start
// ==/UserScript==
(function() {
var css = "";
if (false || (document.domain == "perezhilton.com" ||document.domain.substring(document.domain.indexOf(".perezhilton.com") + 1) == "perezhilton.com") || (document.domain == "fitperez.com" || document.domain.substring(document.domain.indexOf(".fitperez.com") + 1) == "fitperez.com") || (document.domain == "cocoperez.com" || document.domain.substring(document.domain.indexOf(".cocoperez.com") + 1) == "cocoperez.com") || (document.location.href.indexOf("http://perezhilton.com/") == 0))
css += "html { height:100%; background:url(http://i.imgur.com/oqhgG.png) no-repeat center fixed #FFFFFF !important; overflow:hidden; }\n*:not(html) { visibility:hidden; }";
if (typeof GM_addStyle != "undefined") {
GM_addStyle(css);
} else if (typeof PRO_addStyle != "undefined") {
PRO_addStyle(css);
} else if (typeof addStyle != "undefined") {
addStyle(css);
} else {
var heads = document.getElementsByTagName("head");
if (heads.length > 0) {
var node = document.createElement("style");
node.type = "text/css";
node.appendChild(document.createTextNode(css));
heads[0].appendChild(node);
}
}
})();
关于CSS * :not selector in userscript under Google Chrome,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10049246/