1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-12-22 12:50:36 +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");
}
function getBrowserActionIconName(url, notified){
if (isWhitelisted(url)){
function getBrowserActionIconName(tabData, notified){
if (tabData.whitelisted){
return "whitelisted";
}
else if (notified) {
@ -56,12 +56,25 @@
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){
if (settings.ignoredAPIs[api]){
return;
}
logging.notice("Show notification for tab", tabId);
const tabData = getTabData(tabId);
if (
settings.get("showNotifications", url) &&
!lists.get("ignore").match(url)
@ -74,15 +87,11 @@
}
browser.browserAction.setIcon({
tabId: tabId,
path: paths.browserAction[getBrowserActionIconName(url, true)]
path: paths.browserAction[getBrowserActionIconName(tabData, true)]
});
let apis = apiMap.get(tabId);
if (!apis){
apis = new Set();
}
const apis = tabData.apis;
apis.add(api);
apiMap.set(tabId, apis);
if (settings.get("displayBadge", url)){
browser.browserAction.setBadgeText({
tabId: tabId,
@ -96,8 +105,8 @@
});
let browserActionTitle = browser.i18n.getMessage("browserAction_title_default");
if (isWhitelisted(url)){
browserActionTitle += browser.i18n.getMessage("browserAction_title_whitelisted").replace(/{url}/g, url);
if (tabData.whitelisted){
browserActionTitle += browser.i18n.getMessage("browserAction_title_whitelisted").replace(/{url}/g, tabData.url);
}
browserActionTitle += browser.i18n.getMessage("browserAction_title_notified");
browserActionTitle += apiList;
@ -109,7 +118,12 @@
scope.hide = function hideNotification(tabId, url){
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.setIcon({
tabId: tabId,
@ -117,14 +131,14 @@
});
browser.browserAction.setIcon({
tabId: tabId,
path: paths.browserAction[getBrowserActionIconName(url, false)]
path: paths.browserAction[getBrowserActionIconName(tabData, false)]
});
browser.browserAction.setBadgeText({
tabId: tabId,
text: ""
});
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);
}
browser.browserAction.setTitle({
@ -145,7 +159,7 @@
});
browser.tabs.onRemoved.addListener(function(tabId){
apiMap.delete(tabId);
tabsData.delete(tabId);
});
settings.on("displayBadge", function({newValue}){
if (!newValue){