chrome 是否有一个 api 来禁用(并因此变灰)某些 url 上的 chrome 扩展,或者我是否只需要一个 if 语句来检查 url 并相应地切换图标?
最佳答案
你可以使用 chrome.declarativeContent
, 它允许您显示 page action根据网页的 URL 及其内容匹配的 CSS 选择器。
您可以通过 new chrome.declarativeContent.PageStateMatcher
和 new chrome.declarativeContent 这样的构造函数创建条件(是的,您可以使用正则表达式)和操作(
。详细 sample 列于api documentation .ShowPageAction
SetIcon
) .ShowPageAction()
var rule2 = {
conditions: [
new chrome.declarativeContent.PageStateMatcher({
pageUrl: { hostEquals: 'www.google.com', schemes: ['https'] },
css: ["input[type='password']"]
}),
new chrome.declarativeContent.PageStateMatcher({
css: ["video"]
})
],
actions: [ new chrome.declarativeContent.ShowPageAction() ]
};
chrome.runtime.onInstalled.addListener(function(details) {
chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
chrome.declarativeContent.onPageChanged.addRules([rule2]);
});
});
关于javascript - Chrome 扩展 : How do you gray out icon depending on the url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38794273/