开发者

Making a Chrome extension not work on certain pages

开发者 https://www.devze.com 2023-01-25 09:00 出处:网络
I am creating an extension and I need to know how to make a filter, so that it is not activated on certain pages (which the user chooses). I don\'t know much about web开发者_开发知识库 development, so

I am creating an extension and I need to know how to make a filter, so that it is not activated on certain pages (which the user chooses). I don't know much about web开发者_开发知识库 development, so don't think that your solution is 'so easy that it mustn't work'.


You can programatically inject javascript into pages:

//in background.html
var allowedUrlList = ["http://..."];
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
    if(changeInfo.status == "complete") {
        if(allowedUrlList.indexOf(tab.url) != -1) {
            chrome.tabs.executeScript(tabId, {file: "content_script.js"});
        }
    }
});


if (specialPages[document.location.href]) {
    // go away
}
else {
    // do stuff
}

Something like that.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号