mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2024-12-22 12:50:36 +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:",
|
||||
"description": ""
|
||||
},
|
||||
"selectWhitelistScope": {
|
||||
"message": "Was soll erlaubt werden?",
|
||||
"description": ""
|
||||
},
|
||||
"whitelistOnlyAPI": {
|
||||
"message": "Erlaube nur die \"{api}\" API.",
|
||||
"description": ""
|
||||
},
|
||||
"whitelistAllAPIs": {
|
||||
"message": "Erlaube alle APIs.",
|
||||
"description": ""
|
||||
},
|
||||
"settings": {
|
||||
"message": "Einstellungen",
|
||||
"description": ""
|
||||
|
@ -701,6 +701,18 @@
|
||||
"message": "Input URL \"RegExp\" to add to the session whitelist:",
|
||||
"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": {
|
||||
"message": "settings",
|
||||
"description": ""
|
||||
|
@ -76,7 +76,13 @@
|
||||
if (settings.storeNotificationData){
|
||||
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]){
|
||||
sentAPIs[data.api] = true;
|
||||
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){
|
||||
this.urls().add(domain.href);
|
||||
domain = domain.hostname;
|
||||
@ -34,6 +34,7 @@
|
||||
this.domain = domain;
|
||||
this.messageId = messageId;
|
||||
this.count = count;
|
||||
this.api = api;
|
||||
this.extraNotifications = 0;
|
||||
addToContainer(this);
|
||||
this.update();
|
||||
@ -148,7 +149,7 @@
|
||||
DomainNotification.prototype.actionsNode = function actionsNode(){
|
||||
const node = document.createElement("div");
|
||||
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(){
|
||||
return node;
|
||||
};
|
||||
@ -165,11 +166,11 @@
|
||||
};
|
||||
|
||||
const domains = new Map();
|
||||
const domainNotification = function(url, messageId, count = 0){
|
||||
const domainNotification = function(url, messageId, count = 0, api = ""){
|
||||
const domain = url.hostname;
|
||||
var domainNotification = domains.get(domain + messageId);
|
||||
if (!domainNotification){
|
||||
domainNotification = new DomainNotification(url, messageId, count);
|
||||
domainNotification = new DomainNotification(url, messageId, count, api);
|
||||
domains.set(domain + messageId, domainNotification);
|
||||
}
|
||||
else {
|
||||
|
@ -120,15 +120,60 @@
|
||||
{
|
||||
name: "whitelist",
|
||||
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(
|
||||
domain,
|
||||
urls,
|
||||
extension.getTranslation("selectWhitelist"),
|
||||
extension.getTranslation("inputWhitelistURL")
|
||||
).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){
|
||||
settings.set("blockMode", "allow", choice).then(function(){
|
||||
settings.set(setting.name, setting.value, choice).then(function(){
|
||||
window.close();
|
||||
});
|
||||
}
|
||||
@ -184,14 +229,15 @@
|
||||
});
|
||||
|
||||
var tab = tabs[0];
|
||||
browser.runtime.onMessage.addListener(function(data){
|
||||
extension.message.on(function(data){
|
||||
if (data["canvasBlocker-notificationCounter"]){
|
||||
const url = new URL(data.url);
|
||||
Object.keys(data["canvasBlocker-notificationCounter"]).forEach(function(key){
|
||||
const notification = domainNotification(
|
||||
url,
|
||||
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);
|
||||
domainNotification(
|
||||
notification.url,
|
||||
notification.messageId
|
||||
notification.messageId,
|
||||
0,
|
||||
notification.api
|
||||
).addNotification(new Notification(notification));
|
||||
}
|
||||
i += delta;
|
||||
|
Loading…
x
Reference in New Issue
Block a user