mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-07-04 20:46:39 +02:00
parent
c0563cd7d5
commit
bfb959c290
7 changed files with 83 additions and 6 deletions
|
@ -30,7 +30,12 @@
|
|||
}
|
||||
};
|
||||
|
||||
scope.show = function showNotification(tabId, url){
|
||||
browser.browserAction.setBadgeBackgroundColor({
|
||||
color: "rgba(255, 0, 0, 0.6)"
|
||||
});
|
||||
|
||||
const apiMap = new Map();
|
||||
scope.show = function showNotification(tabId, url, api){
|
||||
logging.notice("Show notification for tab", tabId);
|
||||
if (
|
||||
settings.get("showNotifications", url) &&
|
||||
|
@ -46,10 +51,33 @@
|
|||
tabId: tabId,
|
||||
path: paths.browserAction[settings.highlightBrowserAction]
|
||||
});
|
||||
|
||||
let apis = apiMap.get(tabId);
|
||||
if (!apis){
|
||||
apis = new Set();
|
||||
}
|
||||
apis.add(api);
|
||||
apiMap.set(tabId, apis);
|
||||
if (settings.get("displayBadge", url)){
|
||||
browser.browserAction.setBadgeText({
|
||||
tabId: tabId,
|
||||
text: apis.size > 1? apis.size.toString(): api.charAt(0).toUpperCase()
|
||||
});
|
||||
}
|
||||
|
||||
let apiList = "";
|
||||
apis.forEach(function(api){
|
||||
apiList += "\n \u00B7 " + api;
|
||||
});
|
||||
browser.browserAction.setTitle({
|
||||
tabId: tabId,
|
||||
title: "CanvasBlocker" + apiList
|
||||
});
|
||||
};
|
||||
|
||||
scope.hide = function hideNotification(tabId){
|
||||
logging.notice("Hide page action for tab", tabId);
|
||||
apiMap.delete(tabId);
|
||||
browser.pageAction.hide(tabId);
|
||||
browser.pageAction.setIcon({
|
||||
tabId: tabId,
|
||||
|
@ -59,6 +87,14 @@
|
|||
tabId: tabId,
|
||||
path: paths.browserAction.none
|
||||
});
|
||||
browser.browserAction.setBadgeText({
|
||||
tabId: tabId,
|
||||
text: ""
|
||||
});
|
||||
browser.browserAction.setTitle({
|
||||
tabId: tabId,
|
||||
title: "CanvasBlocker"
|
||||
});
|
||||
};
|
||||
|
||||
settings.on("showNotifications", function({newValue}){
|
||||
|
@ -71,4 +107,21 @@
|
|||
});
|
||||
}
|
||||
});
|
||||
|
||||
browser.tabs.onRemoved.addListener(function(tabId){
|
||||
apiMap.delete(tabId);
|
||||
});
|
||||
settings.on("displayBadge", function({newValue}){
|
||||
if (!newValue){
|
||||
logging.message("badge was disabled -> hide all badges");
|
||||
browser.tabs.query({}).then(function(tabs){
|
||||
tabs.forEach(function(tab){
|
||||
browser.browserAction.setBadgeText({
|
||||
tabId: tab.id,
|
||||
text: ""
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}());
|
Loading…
Add table
Add a link
Reference in a new issue