google chrome extension - Event handler when site doesn't match manifest.json 'matches' -
my manifest.json contains block:
"content_scripts": [ { "all_frames": true, "matches": [ "*://www.google.com/*", "*://www.cnn.com/*", "*://*.foxnews.com/*" ], "js": ["js/main.js"] } ],
i need event fire (either in content js or background.js, doesn't matter) whenever user visits website not match 1 of sites in matches
setting.
how done?
in background.js
add listener tab load. in fetch url of current tab , match list.
chrome.tabs.onupdated.addlistener(function(tabid, info, tab) { if (info.status == "complete") { var url = tab.url.replace(/.*?:\/\//g, "").replace(/\/$/, ""); //removes protocol var allowedurls = ["www.google.com", "www.cnn.com", "foxnews.com"]; for(var in allowedurls) { if(allowedurls[i].indexof(url) == -1) { //url not match break; } } } });
Comments
Post a Comment