2017-03-08 40 views
-2

我使用這個腳本[https://userstyles.org/styles/68211/high-visibility-vote-buttons]和使用Tampermonkey使用它在Chrome,我想編輯它,所以它不會對具體的subreddits工作,主要www.reddit .com/r/pcmasterrace,它不能正常使用它們的CSS,如何編輯代碼以在特定頁面上禁用它?編輯腳本,因此它不會對特定版(Subreddit)工作

謝謝。

// ==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

我找到Tampermonkey還有另一種選擇添加排除某些網站。代碼不需要改變,只有腳本的Tampermonkey選項本身。

點擊腳本,然後設置旁邊的首席編輯,請用戶排除,並添加任何URL在那裏。

enter image description here

+1

要確保你的答案是完整的,可以指定哪些選項需要改變? https://stackoverflow.com/help/how-to-answer – TidyDev

0

您可以使用JavaScript中的Location界面查看當前位置。 (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

這不是一個很好的檢查。試想一下:'HTTP://reddit.com/foo引用= reddit.com/R/PC__MasterRace',等等等等 –

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== 

如果你會使用一個@exclude規則你想排除的每個版(Subreddit)。