我使用这个脚本[https://userstyles.org/styles/68211/high-visibility-vote-buttons]并使用Tampermonkey在chrome上使用它,我想编辑它以便它不适用于特定的subreddits,主要是www.reddit.com/r/pcmasterrace,它没有使用他们的CSS正常工作,如何编辑代码以在特定页面上禁用它?
感谢。
// ==UserScript==
// @name High-Visibility Vote Buttons
// @namespace http://userstyles.org
// @description Makes the vote buttons larger and gives them better contrast.
// @author five35
// @homepage https://userstyles.org/styles/68211
// @include http://www.reddit.com/*
// @include https://www.reddit.com/*
// @include http://*.www.reddit.com/*
// @include https://*.www.reddit.com/*
// @run-at document-start
// @version 0.20120626122606
// ==/UserScript==
(function() {var css = [
"@namespace url(http://www.w3.org/1999/xhtml);",
".arrow {",
" height: 20px !important;",
" width: 35px !important;",
" }",
"",
" .comment .midcol, .link .midcol {",
" width: 35px !important;",
" }",
"",
" .arrow.up {",
" background: url(\'data:image/x-png;base64,iVBORw0KGgoAAAANSUhEUgAAACMAAAAUCAMAAAAweHR+AAAAUVBMVEW7u7u7u7u7u7u7u7u7u7u2tra3t7e4uLi7u7u8vLy9vb2+vr7AwMDBwcHCwsLHx8fIyMjKysrNzc3Ozs7T09PU1NTY2Njb29vc3Nzu7u7///8820/+AAAABXRSTlNLT1Ll6MzfsL8AAACJSURBVCjPjdJBFoMgDARQLGQiiWgVEfX+B+3WPivprP8i8zLuFfp2QufCcbZzeNefVvq7gW0Q2TKsELQNJwADWgYJIGDgZwMlIhBI+cmwAAQC8HXT1UBFRAAWFb2gW69ZYpyN7nkcUzbMOk3vYphtWfJmmFrKWg2z11p38+8/tuH/2Fjnja169wG2xDneEz4tNgAAAABJRU5ErkJggg==\') !important;",
" }",
"",
" .arrow.up:hover {",
" background: url(\'data:image/x-png;base64,iVBORw0KGgoAAAANSUhEUgAAACMAAAAUBAMAAAD1iJl/AAAAFVBMVEUzZpkzZpkzZpkzZpkzZpkzZpn///+QQCZsAAAABXRSTlNLT1Ll6MzfsL8AAABSSURBVBjTY1AJRQUhAgyuaEKhBgzoIqEBcKEwTKG0VHShsLQ0dKG0NJgymBBQEUwZTAgkAlUGFQIrgiqDCkFEIMrw2UhjIeTAMcUMQmE0kWAGALgUeKErTIN7AAAAAElFTkSuQmCC\') !important;",
" }",
"",
" .arrow.upmod {",
" background: url(\'data:image/x-png;base64,iVBORw0KGgoAAAANSUhEUgAAACMAAAAUBAMAAAD1iJl/AAAAFVBMVEX/l2//l2//l2//l2//l2//l2////8LenKCAAAABXRSTlNLT1Ll6MzfsL8AAABSSURBVBjTY1AJRQUhAgyuaEKhBgzoIqEBcKEwTKG0VHShsLQ0dKG0NJgymBBQEUwZTAgkAlUGFQIrgiqDCkFEIMrw2UhjIeTAMcUMQmE0kWAGALgUeKErTIN7AAAAAElFTkSuQmCC\') !important;",
" }",
"",
" .arrow.down {",
" background: url(\'data:image/x-png;base64,iVBORw0KGgoAAAANSUhEUgAAACMAAAAUCAMAAAAweHR+AAAAUVBMVEW7u7u7u7u7u7u7u7u7u7u2tra3t7e4uLi7u7u8vLy9vb2+vr7AwMDBwcHCwsLHx8fIyMjKysrNzc3Ozs7T09PU1NTY2Njb29vc3Nzu7u7///8820/+AAAABXRSTlNLT1Ll6MzfsL8AAACNSURBVCjPjdLbEoQgCAZgWxVUOmyZWb7/g0Z3u41JP7ffIA6oj3HtmE6Zo7RzaOWKFHc3e855F0xOac2C2ZYlboJZp+mbBBPHcYiCmYP387MBChwADMQF9T7IwHJxfsjtLSBrL2QJn+eB4eoEPbZmRkbQQ/tfSH+zVE0Bj9JOGRXZVG5Dv7ixTgu3qtUJI2I53raDg/MAAAAASUVORK5CYII=\') !important;",
" }",
"",
" .arrow.down:hover {",
" background: url(\'data:image/x-png;base64,iVBORw0KGgoAAAANSUhEUgAAACMAAAAUBAMAAAD1iJl/AAAAFVBMVEUzZpkzZpkzZpkzZpkzZpkzZpn///+QQCZsAAAABXRSTlNLT1Ll6MzfsL8AAABMSURBVBjTY1AJRQUhAgyuaEKhBgzoIqEBMKGwtDS6CqVBQCqSUBhECEUjQhFcKAyuCGE8XBFeR4TCFCEJhWGEBHLgmGIGoTCaSDADALD0eKHd8GJwAAAAAElFTkSuQmCC\') !important;",
" }",
"",
" .arrow.downmod {",
" background: url(\'data:image/x-png;base64,iVBORw0KGgoAAAANSUhEUgAAACMAAAAUBAMAAAD1iJl/AAAAFVBMVEWfn/+fn/+fn/+fn/+fn/+fn/////8UYO9JAAAABXRSTlNLT1Ll6MzfsL8AAABMSURBVBjTY1AJRQUhAgyuaEKhBgzoIqEBMKGwtDS6CqVBQCqSUBhECEUjQhFcKAyuCGE8XBFeR4TCFCEJhWGEBHLgmGIGoTCaSDADALD0eKHd8GJwAAAAAElFTkSuQmCC\') !important;",
" }"
].join("\n");
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 node = document.createElement("style");
node.type = "text/css";
node.appendChild(document.createTextNode(css));
var heads = document.getElementsByTagName("head");
if (heads.length > 0) {
heads[0].appendChild(node);
} else {
// no head yet, stick it whereever
document.documentElement.appendChild(node);
}
}
})();
答案 0 :(得分:0)
您可以使用Location
界面查看Javascript中的当前位置。 (MDN Reference)。然后,您可以轻松检查用户是否在您要排除的网站上。就像这样:
var href = window.location.href;
/*
as Brock Adams mentioned in the comments:
this may not be the best way to check urls,
since there is of course a possibility of
having url parameters containing the string
you're excluding.
A simple (but no 100% guaranteed) solution would
be doing this:
*/
href = href.split(/[?#]/)[0];
/*
This will split the url on the first "?" or "#"
and return the first part, excluding URL parameters.
So "http://reddit.com/foo?referrer=reddit.com/r/PC__MasterRace"
should become "http://reddit.com/foo"
*/
// check if user isn't on a exluded page
if(href.indexOf("reddit.com/r/PC__MasterRace") === -1){
// do stuff
}
答案 1 :(得分:0)
最简单的方法是使用the @exclude
directive
在这种情况下,可能是a regex rule。
此外,@include
行可以简化为一个@match
把它放在一起,您的元数据块就像:
// ==UserScript==
// @name High-Visibility Vote Buttons
// @match *://*.reddit.com/*
// @exclude /^https?:\/\/.*reddit\.com\/r\/pcmasterrace*/
// @run-at document-start
// ==/UserScript==
您要为要排除的每个subreddit使用一个@exclude
规则。
答案 2 :(得分:0)