我尝试下面的代码,目标是使用自己的firefox插件阻止第三方的所有图像
所以,例如:如果我打开www.test.com页面,我同意看到活动域(www.test.com)的所有图像,但我想阻止所有其他图像(www.boring-ads.com,www .iamthebest.net,...)
var MyPattern= /^((?!goodimg\.net).)*$/ig;
function cancel(requestDetails) {
//console.log("Canceling: " + requestDetails.url);
return {cancel: true};
}
browser.webRequest.onBeforeRequest.addListener(
cancel,
{urls: [MyPattern], types: ["image"]},
["blocking"]
);
来自goodimg.net的所有图片都已加载,但已经来自其他域:(((
为什么? ...使用正则表达式排除字符串是不可能的?
Firefox(或chrome)不使用RegEx来检查网址,请阅读Match_patterns您可以发送模式匹配:
/^(\*|http|https|ws|wss|file|ftp):\/\/(\*|(?:\*\.)?(?:[^\/*]+))?\/(.*)$/
你可以在方法qazxsw poi中使用qazxsw poi和url