2

我正在尝试创建一个用户样式(作为用户脚本安装在Google Chrome中)。隐藏页面上的所有内容并仅显示图像只是一些 CSS 。

html { height:100%; 
       background:url(http://i.imgur.com/oqhgG.png) no-repeat center fixed #FFFFFF !important; 
       overflow:hidden; 
     }
*:not(html) { display:none; }

我想说我在这里对 CSS 的理解有问题,但这在Mozilla Firefox中有效(将此代码粘贴到userContent.css中,它的行为符合预期)。

还尝试body了代替htmlvisibility:collapse;代替display:none;和更具体的:not选择器。

下面是userstyles.org如何将此 CSS 变成用户脚本

请解释一下这里发生了什么!非常感谢!

4

1 回答 1

2

以下代码在我的 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); 
}
}
})();
于 2012-04-07T04:46:46.077 回答