0

我正在寻找用于制作 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"]
);

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

4

1 回答 1

0

文档中,您有以下示例:

chrome.webRequest.onBeforeRequest.addListener(function(details) {
          return {cancel: details.url.indexOf("://www.evil.com/") != -1};
        },
        {urls: ["<all_urls>"]},
        ["blocking"]);

只需更改www.evil.com/pinterest.它将阻止所有pinterest.*页面。如果您想阻止其他子域,例如m.pinterest.comimages.pinterest.com(我不知道这些是否存在),您可以使用 RegExp。

于 2018-01-30T11:55:59.033 回答