1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-06-27 05:52:44 +02:00

Protected notification api calls

Firefox on Android does not support all of them.

Fixes #276
This commit is contained in:
kkapsner 2018-10-02 19:23:59 +02:00
parent d4d0d80721
commit 3a7c15157c

View File

@ -52,9 +52,11 @@
} }
}; };
if (browser.browserAction.setBadgeBackgroundColor){
browser.browserAction.setBadgeBackgroundColor({ browser.browserAction.setBadgeBackgroundColor({
color: "rgba(255, 0, 0, 0.6)" color: "rgba(255, 0, 0, 0.6)"
}); });
}
const tabsData = new Map(); const tabsData = new Map();
function getTabData(tabId){ function getTabData(tabId){
@ -80,19 +82,26 @@
!lists.get("ignore").match(url) !lists.get("ignore").match(url)
){ ){
browser.pageAction.show(tabId); browser.pageAction.show(tabId);
if (browser.pageAction.setIcon){
browser.pageAction.setIcon({ browser.pageAction.setIcon({
tabId: tabId, tabId: tabId,
path: paths.pageAction[settings.highlightPageAction] path: paths.pageAction[settings.highlightPageAction]
}); });
} }
}
if (browser.browserAction.setIcon){
browser.browserAction.setIcon({ browser.browserAction.setIcon({
tabId: tabId, tabId: tabId,
path: paths.browserAction[getBrowserActionIconName(tabData, true)] path: paths.browserAction[getBrowserActionIconName(tabData, true)]
}); });
}
const apis = tabData.apis; const apis = tabData.apis;
apis.add(api); apis.add(api);
if (settings.get("displayBadge", url)){ if (
settings.get("displayBadge", url) &&
browser.browserAction.setBadgeText
){
browser.browserAction.setBadgeText({ browser.browserAction.setBadgeText({
tabId: tabId, tabId: tabId,
text: apis.size > 1? apis.size.toString(): api.charAt(0).toUpperCase() text: apis.size > 1? apis.size.toString(): api.charAt(0).toUpperCase()
@ -126,18 +135,24 @@
tabData.whitelisted = isWhitelisted(url); tabData.whitelisted = isWhitelisted(url);
browser.pageAction.hide(tabId); browser.pageAction.hide(tabId);
if (browser.pageAction.setIcon){
browser.pageAction.setIcon({ browser.pageAction.setIcon({
tabId: tabId, tabId: tabId,
path: paths.pageAction.none path: paths.pageAction.none
}); });
}
if (browser.browserAction.setIcon){
browser.browserAction.setIcon({ browser.browserAction.setIcon({
tabId: tabId, tabId: tabId,
path: paths.browserAction[getBrowserActionIconName(tabData, false)] path: paths.browserAction[getBrowserActionIconName(tabData, false)]
}); });
}
if (browser.browserAction.setBadgeText){
browser.browserAction.setBadgeText({ browser.browserAction.setBadgeText({
tabId: tabId, tabId: tabId,
text: "" text: ""
}); });
}
let browserActionTitle = browser.i18n.getMessage("browserAction_title_default"); let browserActionTitle = browser.i18n.getMessage("browserAction_title_default");
if (tabData.whitelisted){ if (tabData.whitelisted){
browserActionTitle += browser.i18n.getMessage("browserAction_title_whitelisted").replace(/{url}/g, url); browserActionTitle += browser.i18n.getMessage("browserAction_title_whitelisted").replace(/{url}/g, url);
@ -165,6 +180,7 @@
settings.on("displayBadge", function({newValue}){ settings.on("displayBadge", function({newValue}){
if (!newValue){ if (!newValue){
logging.message("badge was disabled -> hide all badges"); logging.message("badge was disabled -> hide all badges");
if (browser.browserAction.setBadgeText){
browser.tabs.query({}).then(function(tabs){ browser.tabs.query({}).then(function(tabs){
tabs.forEach(function(tab){ tabs.forEach(function(tab){
browser.browserAction.setBadgeText({ browser.browserAction.setBadgeText({
@ -174,5 +190,6 @@
}); });
}); });
} }
}
}); });
}()); }());