我正在寻找一个匹配模式规则的解决方案,用于制作Google Chrome扩展-我正在尝试屏蔽Pinterest等网站,问题是Pinterest有一百万个TLD,而不是写出来……
永远的"*://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"]
);上面的代码可以工作。任何人有任何想法如何做到这一点,任何推动在正确的方向,将不胜感激。非常感谢。
发布于 2018-01-30 19:55:59
在documentation中,您可以看到以下示例:
chrome.webRequest.onBeforeRequest.addListener(function(details) {
return {cancel: details.url.indexOf("://www.evil.com/") != -1};
},
{urls: ["<all_urls>"]},
["blocking"]);只需通过pinterest.更改www.evil.com/,它就会阻止所有pinterest.*页面。如果你想屏蔽其他的子域,比如m.pinterest.com或者images.pinterest.com (我甚至不知道它们是否存在),你可以使用RegExp。
https://stackoverflow.com/questions/48519360
复制相似问题