我是Chrome扩展开发的新手,并且具有以下代码段
var toggle = false;
chrome.browserAction.onClicked.addListener(function(tab) {
toggle = !toggle;
if(toggle){
chrome.browserAction.setIcon({path: "on.png", tabId:tab.id});
chrome.webRequest.onBeforeRequest.addListener(function(details) {
return {cancel: true};
},
{urls: ["https://www.google.com/*", "http://www.dictionary.com/*"]},
["blocking"]);
}
else{
chrome.browserAction.setIcon({path: "off.png", tabId:tab.id});
//insert unblock code or remove listener code
}
});
基本上,我想制作一个Chrome扩展程序,以便在用户点击扩展程序图标时切换网站屏蔽
我已经提到这个了,没有运气 https://medium.com/@DavideRama/removeeventlistener-and-anonymous-functions-ab9dbabd3e7b