Alright, so let me make a few changes to your manifest and background pages.
manifest.json
"browser_action": {
"default_icon": "off.png",
"default_title": "icon"
},
That will make the default off.png
. As for the icons section, read the docs to see what it is used for, but for now just remove it entirely. Also remove what you have in your contentScripts section. If you want to inject it programmatically then there is no need to list it in the manifest.
Next some changes to your background page to make it a bit more clean:
background.js
var toggle = false;
chrome.browserAction.onClicked.addListener(function(tab) {
toggle = !toggle;
if(toggle){
chrome.browserAction.setIcon({path: "on.png", tabId:tab.id});
chrome.tabs.executeScript(tab.id, {file:"SCRIPT.user.js"});
}
else{
chrome.browserAction.setIcon({path: "off.png", tabId:tab.id});
chrome.tabs.executeScript(tab.id, {code:"alert()"});
}
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…