阻止Chrome扩展程序中每个顶级域名的域名

时间:2018-01-30 10:38:35

标签: javascript google-chrome google-chrome-extension manifest.json

我正在寻找制作Google Chrome扩展程序的匹配模式规则的解决方案 - 我试图阻止像Pinterest这样的网站,问题是Pinterest有一百万个顶级域名而不是写出...

永远

"*://pinterest.com/*, *://pinterest.se/*, *://pinterest.co.uk/*..

我试图阻止所有Pinterest的顶级域名。

使用"*://pinterest.*/*""*://*.pinterest.*/*"不起作用。

var blockedUrls = [ "*://*.pinterest.se/*, *://*.pinterest.com/*"];


var host = "https://www.google.com"


chrome.webRequest.onBeforeRequest.addListener(
function(details) {
     return {redirectUrl: host };
},
{
    urls:blockedUrls,

    types: ["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xmlhttprequest", "other"]
},
["blocking"]
);

以上代码有效。 任何人都知道如何做到这一点,任何正确方向的推动将不胜感激。 非常感谢。

1 个答案:

答案 0 :(得分:0)

documentation中你有这个例子:

www.evil.com/

只需按pinterest.更改pinterest.*即可阻止所有m.pinterest.com页面。如果您想屏蔽其他子域名,例如images.pinterest.com或{{1}}(我不知道这些是否存在),您可以使用RegExp。