mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-01-03 10:31:54 +01:00
Added whitelist scope question
This commit is contained in:
parent
cd8c7bd71c
commit
51445b36e0
@ -667,6 +667,18 @@
|
|||||||
"message": "Geben Sie die URL \"RegExp\" ein, die für diese Sitzung erlaubt werden soll:",
|
"message": "Geben Sie die URL \"RegExp\" ein, die für diese Sitzung erlaubt werden soll:",
|
||||||
"description": ""
|
"description": ""
|
||||||
},
|
},
|
||||||
|
"selectWhitelistScope": {
|
||||||
|
"message": "Was soll erlaubt werden?",
|
||||||
|
"description": ""
|
||||||
|
},
|
||||||
|
"whitelistOnlyAPI": {
|
||||||
|
"message": "Erlaube nur die \"{api}\" API.",
|
||||||
|
"description": ""
|
||||||
|
},
|
||||||
|
"whitelistAllAPIs": {
|
||||||
|
"message": "Erlaube alle APIs.",
|
||||||
|
"description": ""
|
||||||
|
},
|
||||||
"settings": {
|
"settings": {
|
||||||
"message": "Einstellungen",
|
"message": "Einstellungen",
|
||||||
"description": ""
|
"description": ""
|
||||||
|
@ -701,6 +701,18 @@
|
|||||||
"message": "Input URL \"RegExp\" to add to the session whitelist:",
|
"message": "Input URL \"RegExp\" to add to the session whitelist:",
|
||||||
"description": ""
|
"description": ""
|
||||||
},
|
},
|
||||||
|
"selectWhitelistScope": {
|
||||||
|
"message": "What is the scope of the whitelisting?",
|
||||||
|
"description": ""
|
||||||
|
},
|
||||||
|
"whitelistOnlyAPI": {
|
||||||
|
"message": "Whitelist only the API \"{api}\".",
|
||||||
|
"description": ""
|
||||||
|
},
|
||||||
|
"whitelistAllAPIs": {
|
||||||
|
"message": "Whitelist all APIs.",
|
||||||
|
"description": ""
|
||||||
|
},
|
||||||
"settings": {
|
"settings": {
|
||||||
"message": "settings",
|
"message": "settings",
|
||||||
"description": ""
|
"description": ""
|
||||||
|
@ -76,7 +76,13 @@
|
|||||||
if (settings.storeNotificationData){
|
if (settings.storeNotificationData){
|
||||||
notifications.push(data);
|
notifications.push(data);
|
||||||
}
|
}
|
||||||
notificationCounter[data.messageId] = (notificationCounter[data.messageId] || 0) + 1;
|
if (!notificationCounter[data.messageId]){
|
||||||
|
notificationCounter[data.messageId] = {
|
||||||
|
count: 0,
|
||||||
|
api: data.api
|
||||||
|
};
|
||||||
|
}
|
||||||
|
notificationCounter[data.messageId].count += 1;
|
||||||
if (!sentAPIs[data.api]){
|
if (!sentAPIs[data.api]){
|
||||||
sentAPIs[data.api] = true;
|
sentAPIs[data.api] = true;
|
||||||
port.postMessage({"canvasBlocker-notify": data});
|
port.postMessage({"canvasBlocker-notify": data});
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
};
|
};
|
||||||
}();
|
}();
|
||||||
|
|
||||||
const DomainNotification = function DomainNotification(domain, messageId, count = 0){
|
const DomainNotification = function DomainNotification(domain, messageId, count = 0, api = ""){
|
||||||
if (domain instanceof URL){
|
if (domain instanceof URL){
|
||||||
this.urls().add(domain.href);
|
this.urls().add(domain.href);
|
||||||
domain = domain.hostname;
|
domain = domain.hostname;
|
||||||
@ -34,6 +34,7 @@
|
|||||||
this.domain = domain;
|
this.domain = domain;
|
||||||
this.messageId = messageId;
|
this.messageId = messageId;
|
||||||
this.count = count;
|
this.count = count;
|
||||||
|
this.api = api;
|
||||||
this.extraNotifications = 0;
|
this.extraNotifications = 0;
|
||||||
addToContainer(this);
|
addToContainer(this);
|
||||||
this.update();
|
this.update();
|
||||||
@ -148,7 +149,7 @@
|
|||||||
DomainNotification.prototype.actionsNode = function actionsNode(){
|
DomainNotification.prototype.actionsNode = function actionsNode(){
|
||||||
const node = document.createElement("div");
|
const node = document.createElement("div");
|
||||||
node.className = "actions";
|
node.className = "actions";
|
||||||
createActionButtons(node, actions, {domain: this.domain, urls: this.urls()});
|
createActionButtons(node, actions, {domain: this.domain, urls: this.urls(), api: this.api});
|
||||||
this.actionsNode = function(){
|
this.actionsNode = function(){
|
||||||
return node;
|
return node;
|
||||||
};
|
};
|
||||||
@ -165,11 +166,11 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
const domains = new Map();
|
const domains = new Map();
|
||||||
const domainNotification = function(url, messageId, count = 0){
|
const domainNotification = function(url, messageId, count = 0, api = ""){
|
||||||
const domain = url.hostname;
|
const domain = url.hostname;
|
||||||
var domainNotification = domains.get(domain + messageId);
|
var domainNotification = domains.get(domain + messageId);
|
||||||
if (!domainNotification){
|
if (!domainNotification){
|
||||||
domainNotification = new DomainNotification(url, messageId, count);
|
domainNotification = new DomainNotification(url, messageId, count, api);
|
||||||
domains.set(domain + messageId, domainNotification);
|
domains.set(domain + messageId, domainNotification);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -120,15 +120,60 @@
|
|||||||
{
|
{
|
||||||
name: "whitelist",
|
name: "whitelist",
|
||||||
isIcon: true,
|
isIcon: true,
|
||||||
callback: function({domain, urls}){
|
callback: function({domain, urls, api}){
|
||||||
|
const whitelistingSettings = {
|
||||||
|
all: {name: "blockMode", value: "allow"},
|
||||||
|
canvas: {name: "protectedCanvasPart", value: "nothing"},
|
||||||
|
audio: {name: "protectAudio", value: false},
|
||||||
|
domRect: {name: "protectDOMRect", value: false},
|
||||||
|
history: {name: "historyLengthThreshold", value: 10000},
|
||||||
|
navigator: {name: "protectNavigator", value: false},
|
||||||
|
windows: {name: "protectWindow", value: false}
|
||||||
|
|
||||||
|
};
|
||||||
domainOrUrlPicker(
|
domainOrUrlPicker(
|
||||||
domain,
|
domain,
|
||||||
urls,
|
urls,
|
||||||
extension.getTranslation("selectWhitelist"),
|
extension.getTranslation("selectWhitelist"),
|
||||||
extension.getTranslation("inputWhitelistURL")
|
extension.getTranslation("inputWhitelistURL")
|
||||||
).then(function(choice){
|
).then(function(choice){
|
||||||
|
const allAPIs = {
|
||||||
|
choice,
|
||||||
|
setting: "blockMode",
|
||||||
|
settingValue: "allow"
|
||||||
|
};
|
||||||
|
const onlyAPI = {
|
||||||
|
choice,
|
||||||
|
setting: whitelistingSettings[api],
|
||||||
|
settingValue: false
|
||||||
|
};
|
||||||
|
if (
|
||||||
|
api &&
|
||||||
|
whitelistingSettings[api]
|
||||||
|
){
|
||||||
|
return modalChoice(
|
||||||
|
extension.getTranslation("selectWhitelistScope"),
|
||||||
|
[
|
||||||
|
{
|
||||||
|
text: extension.getTranslation("whitelistOnlyAPI")
|
||||||
|
.replace(/\{api\}/g, api),
|
||||||
|
value: api
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: extension.getTranslation("whitelistAllAPIs"),
|
||||||
|
value: "all"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
).then(function(selection){
|
||||||
|
return {choice, setting: whitelistingSettings[selection]};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return {choice, setting: whitelistingSettings.all};
|
||||||
|
}
|
||||||
|
}).then(function({choice, setting}){
|
||||||
if (choice){
|
if (choice){
|
||||||
settings.set("blockMode", "allow", choice).then(function(){
|
settings.set(setting.name, setting.value, choice).then(function(){
|
||||||
window.close();
|
window.close();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -184,14 +229,15 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
var tab = tabs[0];
|
var tab = tabs[0];
|
||||||
browser.runtime.onMessage.addListener(function(data){
|
extension.message.on(function(data){
|
||||||
if (data["canvasBlocker-notificationCounter"]){
|
if (data["canvasBlocker-notificationCounter"]){
|
||||||
const url = new URL(data.url);
|
const url = new URL(data.url);
|
||||||
Object.keys(data["canvasBlocker-notificationCounter"]).forEach(function(key){
|
Object.keys(data["canvasBlocker-notificationCounter"]).forEach(function(key){
|
||||||
const notification = domainNotification(
|
const notification = domainNotification(
|
||||||
url,
|
url,
|
||||||
key,
|
key,
|
||||||
data["canvasBlocker-notificationCounter"][key]
|
data["canvasBlocker-notificationCounter"][key].count,
|
||||||
|
data["canvasBlocker-notificationCounter"][key].api
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -218,7 +264,9 @@
|
|||||||
notification.url = new URL(notification.url);
|
notification.url = new URL(notification.url);
|
||||||
domainNotification(
|
domainNotification(
|
||||||
notification.url,
|
notification.url,
|
||||||
notification.messageId
|
notification.messageId,
|
||||||
|
0,
|
||||||
|
notification.api
|
||||||
).addNotification(new Notification(notification));
|
).addNotification(new Notification(notification));
|
||||||
}
|
}
|
||||||
i += delta;
|
i += delta;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user