1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-06-20 02:22:46 +02:00

Merge branch 'whitelistedIndicator'

Fixes #241
This commit is contained in:
kkapsner 2018-09-16 14:08:00 +02:00
commit f8de9b9539
7 changed files with 202 additions and 17 deletions

View File

@ -28,6 +28,7 @@
"spodermenpls", "spodermenpls",
"unticking", "unticking",
"webgl", "webgl",
"whitelisted",
"yfdyh" "yfdyh"
], ],
"cSpell.language": "en,de,en-GB" "cSpell.language": "en,de,en-GB"

View File

@ -13,7 +13,11 @@
"description": "" "description": ""
}, },
"browserAction_title_notified": { "browserAction_title_notified": {
"message": "CanvasBlocker \n\nSchutz erfolgreich für:", "message": " \n\nSchutz erfolgreich für:",
"description": ""
},
"browserAction_title_whitelisted": {
"message": " (APIs erlaubt für {url})",
"description": "" "description": ""
}, },
"browserAction_title_protectedAPIs": { "browserAction_title_protectedAPIs": {

View File

@ -13,7 +13,11 @@
"description": "" "description": ""
}, },
"browserAction_title_notified": { "browserAction_title_notified": {
"message": "CanvasBlocker \n\nprotection successful for:", "message": " \n\nprotection successful for:",
"description": ""
},
"browserAction_title_whitelisted": {
"message": " (APIs whitelisted for {url})",
"description": "" "description": ""
}, },
"browserAction_title_protectedAPIs": { "browserAction_title_protectedAPIs": {

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -65,7 +65,7 @@
notification.show(port.sender.tab.id, url, data["canvasBlocker-notify"].api); notification.show(port.sender.tab.id, url, data["canvasBlocker-notify"].api);
} }
if (data.hasOwnProperty("canvasBlocker-clear-page-action")){ if (data.hasOwnProperty("canvasBlocker-clear-page-action")){
notification.hide(port.sender.tab.id); notification.hide(port.sender.tab.id, url);
} }
verbose("got data", data, "from port", port); verbose("got data", data, "from port", port);
}); });

View File

@ -17,6 +17,27 @@
const lists = require("./lists"); const lists = require("./lists");
const logging = require("./logging"); const logging = require("./logging");
function isWhitelisted(url){
if (!(url instanceof URL)){
url = new URL(url);
}
return lists.get("white").match(url) ||
lists.get("sessionWhite").match(url) ||
settings.get("blockMode", url).startsWith("allow");
}
function getBrowserActionIconName(tabData, notified){
if (tabData.whitelisted){
return "whitelisted";
}
else if (notified) {
return settings.highlightBrowserAction;
}
else {
return "none";
}
}
const paths = { const paths = {
pageAction: { pageAction: {
none: "icons/pageAction-printed.svg", none: "icons/pageAction-printed.svg",
@ -26,7 +47,8 @@
browserAction: { browserAction: {
none: "icons/browserAction-notPrinted.svg", none: "icons/browserAction-notPrinted.svg",
color: "icons/browserAction-printed.svg", color: "icons/browserAction-printed.svg",
blink: "icons/browserAction-printedBlink.svg" blink: "icons/browserAction-printedBlink.svg",
whitelisted: "icons/browserAction-whitelisted.svg"
} }
}; };
@ -34,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)
@ -52,15 +87,11 @@
} }
browser.browserAction.setIcon({ browser.browserAction.setIcon({
tabId: tabId, tabId: tabId,
path: paths.browserAction[settings.highlightBrowserAction] 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,
@ -72,15 +103,27 @@
apis.forEach(function(api){ apis.forEach(function(api){
apiList += browser.i18n.getMessage("browserAction_title_protectedAPIs").replace(/{api}/g, api); apiList += browser.i18n.getMessage("browserAction_title_protectedAPIs").replace(/{api}/g, api);
}); });
let browserActionTitle = browser.i18n.getMessage("browserAction_title_default");
if (tabData.whitelisted){
browserActionTitle += browser.i18n.getMessage("browserAction_title_whitelisted").replace(/{url}/g, tabData.url);
}
browserActionTitle += browser.i18n.getMessage("browserAction_title_notified");
browserActionTitle += apiList;
browser.browserAction.setTitle({ browser.browserAction.setTitle({
tabId: tabId, tabId: tabId,
title: browser.i18n.getMessage("browserAction_title_notified") + apiList title: browserActionTitle
}); });
}; };
scope.hide = function hideNotification(tabId){ 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,
@ -88,15 +131,19 @@
}); });
browser.browserAction.setIcon({ browser.browserAction.setIcon({
tabId: tabId, tabId: tabId,
path: paths.browserAction.none 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");
if (tabData.whitelisted){
browserActionTitle += browser.i18n.getMessage("browserAction_title_whitelisted").replace(/{url}/g, url);
}
browser.browserAction.setTitle({ browser.browserAction.setTitle({
tabId: tabId, tabId: tabId,
title: browser.i18n.getMessage("browserAction_title_default") title: browserActionTitle
}); });
}; };
@ -112,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){

View File

@ -10,6 +10,7 @@ Version 0.5.4:
- added protection for DOMRect (getClientRects) - added protection for DOMRect (getClientRects)
- added setting to control if notification details should be stored - added setting to control if notification details should be stored
- state of the arrow for url specific values is saved - state of the arrow for url specific values is saved
- browser action icon gets grayed out if the page is whitelisted
fixes: fixes:
- window and audio API were always blocked when using any of the "block ..." modes - window and audio API were always blocked when using any of the "block ..." modes