我正在制作一个非常简单的 Chrome 扩展程序来阻止对某些域的请求(厌倦了许多网站上缓慢的页面加载,等待 facebook 垃圾邮件)。我的问题是关于如何有效地加载用户指定的域列表。Chrome 文档指出,将包含“url”的映射传递给 addListener 调用比传入所有请求并在我的函数中检查它们更有效。我该怎么做,但使用用户提供的域/表达式列表?
到目前为止,这是我的清单和 js 文件:
清单.json
{
"name": "I Don't Want YOur Social Networking Junk",
"version": "1.0",
"description": "This extension let's you block (Chrome will not download) content from domains. Too many sites slow themselves down by bringing in a bunch of junk from sites like facebook. This will let you block those things.",
"permissions": ["webRequest", "webRequestBlocking", "http://*/*", "https://*/*"],
"background": {
"scripts": ["background.js"]
},
"manifest_version": 2
}
背景.js
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
return {cancel: true};
}, { urls: ["*://*.facebook.com/*", "*://*.facebook.net/*"] }, ["blocking"]);
正如你所看到的,我现在在 urls 列表中有几个硬编码的表达式。这就是我想从用户可以填充的内容中加载的内容。建议?