1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-12-22 21:00:23 +01:00

Only use whitelisted status of tab url

For #241
This commit is contained in:
kkapsner 2018-09-08 00:44:37 +02:00
parent 6477572f79
commit e147c119ef

View File

@ -26,8 +26,8 @@
settings.get("blockMode", url).startsWith("allow"); settings.get("blockMode", url).startsWith("allow");
} }
function getBrowserActionIconName(url, notified){ function getBrowserActionIconName(tabData, notified){
if (isWhitelisted(url)){ if (tabData.whitelisted){
return "whitelisted"; return "whitelisted";
} }
else if (notified) { else if (notified) {
@ -56,12 +56,25 @@
color: "rgba(255, 0, 0, 0.6)" color: "rgba(255, 0, 0, 0.6)"
}); });
const apiMap = new Map(); const tabsData = new Map();
function getTabData(tabId){
let data = tabsData.get(tabId);
if (!data){
data = {
url: "",
apis: new Set(),
whitelisted: false
};
tabsData.set(tabId, data);
}
return data;
}
scope.show = function showNotification(tabId, url, api){ scope.show = function showNotification(tabId, url, api){
if (settings.ignoredAPIs[api]){ if (settings.ignoredAPIs[api]){
return; return;
} }
logging.notice("Show notification for tab", tabId); logging.notice("Show notification for tab", tabId);
const tabData = getTabData(tabId);
if ( if (
settings.get("showNotifications", url) && settings.get("showNotifications", url) &&
!lists.get("ignore").match(url) !lists.get("ignore").match(url)
@ -74,15 +87,11 @@
} }
browser.browserAction.setIcon({ browser.browserAction.setIcon({
tabId: tabId, tabId: tabId,
path: paths.browserAction[getBrowserActionIconName(url, true)] path: paths.browserAction[getBrowserActionIconName(tabData, true)]
}); });
let apis = apiMap.get(tabId); const apis = tabData.apis;
if (!apis){
apis = new Set();
}
apis.add(api); apis.add(api);
apiMap.set(tabId, apis);
if (settings.get("displayBadge", url)){ if (settings.get("displayBadge", url)){
browser.browserAction.setBadgeText({ browser.browserAction.setBadgeText({
tabId: tabId, tabId: tabId,
@ -96,8 +105,8 @@
}); });
let browserActionTitle = browser.i18n.getMessage("browserAction_title_default"); let browserActionTitle = browser.i18n.getMessage("browserAction_title_default");
if (isWhitelisted(url)){ if (tabData.whitelisted){
browserActionTitle += browser.i18n.getMessage("browserAction_title_whitelisted").replace(/{url}/g, url); browserActionTitle += browser.i18n.getMessage("browserAction_title_whitelisted").replace(/{url}/g, tabData.url);
} }
browserActionTitle += browser.i18n.getMessage("browserAction_title_notified"); browserActionTitle += browser.i18n.getMessage("browserAction_title_notified");
browserActionTitle += apiList; browserActionTitle += apiList;
@ -109,7 +118,12 @@
scope.hide = function hideNotification(tabId, url){ scope.hide = function hideNotification(tabId, url){
logging.notice("Hide page action for tab", tabId); logging.notice("Hide page action for tab", tabId);
apiMap.delete(tabId); // clear old data
tabsData.delete(tabId);
const tabData = getTabData(tabId);
tabData.url = url;
tabData.whitelisted = isWhitelisted(url);
browser.pageAction.hide(tabId); browser.pageAction.hide(tabId);
browser.pageAction.setIcon({ browser.pageAction.setIcon({
tabId: tabId, tabId: tabId,
@ -117,14 +131,14 @@
}); });
browser.browserAction.setIcon({ browser.browserAction.setIcon({
tabId: tabId, tabId: tabId,
path: paths.browserAction[getBrowserActionIconName(url, false)] path: paths.browserAction[getBrowserActionIconName(tabData, false)]
}); });
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 (isWhitelisted(url)){ 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);
} }
browser.browserAction.setTitle({ browser.browserAction.setTitle({
@ -145,7 +159,7 @@
}); });
browser.tabs.onRemoved.addListener(function(tabId){ browser.tabs.onRemoved.addListener(function(tabId){
apiMap.delete(tabId); tabsData.delete(tabId);
}); });
settings.on("displayBadge", function({newValue}){ settings.on("displayBadge", function({newValue}){
if (!newValue){ if (!newValue){