Show badge-notification if active on tab

Tabs-permission needed for tab-url (manifest.json).
This commit is contained in:
magnolia1234 2020-03-03 22:37:45 +01:00 committed by GitHub
parent 1bdc928d8f
commit a419439bc9
2 changed files with 22 additions and 0 deletions

View File

@ -455,6 +455,27 @@ browser.webRequest.onBeforeSendHeaders.addListener(function(details) {
urls: ['<all_urls>']
}, ['blocking', 'requestHeaders']);
browser.tabs.onUpdated.addListener(updateBadge);
browser.tabs.onActivated.addListener(updateBadge);
function updateBadge() {
browser.tabs.query({
active: true,
currentWindow: true
}, function (arrayOfTabs) {
var activeTab = arrayOfTabs[0];
if (!activeTab)
return;
var textB = getTextB(activeTab.url);
browser.browserAction.setBadgeBackgroundColor({color: "red"});
browser.browserAction.setBadgeText({text: textB});
});
}
function getTextB(currentUrl) {
return currentUrl && isSiteEnabled({url: currentUrl}) ? 'ON' : '';
}
// remove cookies after page load
browser.webRequest.onCompleted.addListener(function(details) {
for (var domainIndex in remove_cookies) {

View File

@ -36,6 +36,7 @@
"cookies",
"<all_urls>",
"storage",
"tabs",
"webRequest",
"webRequestBlocking"
],