mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-07-03 20:16:33 +02:00
Changed to getter approach
- no "visible vs. invisible" possible
This commit is contained in:
parent
b2f6aee8f9
commit
147a2893c4
6 changed files with 196 additions and 309 deletions
152
lib/main.js
152
lib/main.js
|
@ -42,12 +42,18 @@
|
|||
|
||||
var self = require("sdk/self");
|
||||
var pageMod = require("sdk/page-mod");
|
||||
var array = require("sdk/util/array");
|
||||
var preferences = require("sdk/simple-prefs");
|
||||
var prefs = preferences.prefs;
|
||||
var {URL} = require("sdk/url");
|
||||
var _ = require("sdk/l10n").get;
|
||||
|
||||
// preferences
|
||||
Object.keys(prefs).forEach(function(pref){
|
||||
preferences.on(pref, function(){
|
||||
workers.forEach(checkWorker);
|
||||
});
|
||||
});
|
||||
var whiteList;
|
||||
function updateWhiteList(){
|
||||
whiteList = getDomainRegExpList(prefs.whiteList);
|
||||
|
@ -55,7 +61,6 @@
|
|||
updateWhiteList();
|
||||
preferences.on("whiteList", function(){
|
||||
updateWhiteList();
|
||||
// workers.forEach(checkWorker);
|
||||
});
|
||||
|
||||
var blackList;
|
||||
|
@ -65,100 +70,84 @@
|
|||
updateBlackList();
|
||||
preferences.on("blackList", function(){
|
||||
updateBlackList();
|
||||
// workers.forEach(checkWorker);
|
||||
});
|
||||
|
||||
|
||||
// preferences.on("blockMode", function(){
|
||||
// workers.forEach(checkWorker);
|
||||
// });
|
||||
// preferences.on("allowPDFCanvas", function(){
|
||||
// workers.forEach(checkWorker);
|
||||
// });
|
||||
|
||||
// var workers = [];
|
||||
// function detachWorker(worker, workerArray) {
|
||||
// var index = workerArray.indexOf(worker);
|
||||
// if (index !== -1){
|
||||
// workerArray.splice(index, 1);
|
||||
// }
|
||||
// }
|
||||
function checkWorker(worker){
|
||||
var url = new URL(worker.url);
|
||||
var mode = "block";
|
||||
switch (prefs.blockMode){
|
||||
case "blockEverything":
|
||||
mode = "block";
|
||||
break;
|
||||
case "allowOnlyWhiteList":
|
||||
if (whiteList.match(url)){
|
||||
mode = "unblock";
|
||||
}
|
||||
else {
|
||||
try {
|
||||
var url = new URL(worker.url);
|
||||
var mode = "block";
|
||||
switch (prefs.blockMode){
|
||||
case "blockEverything":
|
||||
mode = "block";
|
||||
}
|
||||
break;
|
||||
case "askVisible":
|
||||
if (whiteList.match(url)){
|
||||
break;
|
||||
case "allowOnlyWhiteList":
|
||||
if (whiteList.match(url)){
|
||||
mode = "unblock";
|
||||
}
|
||||
else {
|
||||
mode = "block";
|
||||
}
|
||||
break;
|
||||
case "ask":
|
||||
if (whiteList.match(url)){
|
||||
mode = "unblock";
|
||||
}
|
||||
else if (blackList.match(url)){
|
||||
mode = "block";
|
||||
}
|
||||
else {
|
||||
mode = "ask";
|
||||
}
|
||||
break;
|
||||
case "blockReadout":
|
||||
if (whiteList.match(url)){
|
||||
mode = "unblock";
|
||||
}
|
||||
else if (blackList.match(url)){
|
||||
mode = "block";
|
||||
}
|
||||
else {
|
||||
mode = "blockReadout";
|
||||
}
|
||||
break;
|
||||
case "blockOnlyBlackList":
|
||||
if (blackList.match(url)){
|
||||
mode = "block";
|
||||
}
|
||||
else {
|
||||
mode = "unblock";
|
||||
}
|
||||
break;
|
||||
case "allowEverything":
|
||||
mode = "unblock";
|
||||
}
|
||||
else if (blackList.match(url)){
|
||||
mode = "block";
|
||||
}
|
||||
else {
|
||||
mode = "askVisible";
|
||||
}
|
||||
break;
|
||||
case "askInvisible":
|
||||
if (whiteList.match(url)){
|
||||
mode = "unblock";
|
||||
}
|
||||
else if (blackList.match(url)){
|
||||
mode = "block";
|
||||
}
|
||||
else {
|
||||
mode = "askInvisible";
|
||||
}
|
||||
break;
|
||||
case "blockReadout":
|
||||
if (whiteList.match(url)){
|
||||
mode = "unblock";
|
||||
}
|
||||
else if (blackList.match(url)){
|
||||
mode = "block";
|
||||
}
|
||||
else {
|
||||
mode = "blockReadout";
|
||||
}
|
||||
break;
|
||||
case "blockOnlyBlackList":
|
||||
if (blackList.match(url)){
|
||||
mode = "block";
|
||||
}
|
||||
else {
|
||||
mode = "unblock";
|
||||
}
|
||||
break;
|
||||
case "allowEverything":
|
||||
mode = "unblock";
|
||||
break;
|
||||
default:
|
||||
console.log("Unknown blocking mode. Default to block everything.");
|
||||
break;
|
||||
default:
|
||||
console.log("Unknown blocking mode. Default to block everything.");
|
||||
}
|
||||
worker.port.emit(mode, false, prefs.askOnlyOnce);
|
||||
}
|
||||
catch (e){
|
||||
console.log("Error updating " + worker.url + ": " + e.message);
|
||||
}
|
||||
worker.port.emit(mode, false, prefs.askOnlyOnce);
|
||||
}
|
||||
|
||||
|
||||
var workers = [];
|
||||
pageMod.PageMod({
|
||||
include: "*",
|
||||
contentScriptWhen: "start",
|
||||
contentScriptFile: self.data.url("inject.js"),
|
||||
onAttach: function(worker){
|
||||
|
||||
// workers.push(worker);
|
||||
// worker.on("detach", function(){
|
||||
// detachWorker(this, workers);
|
||||
// });
|
||||
array.add(workers, worker);
|
||||
worker.on("pageshow", function(){
|
||||
array.add(workers, this);
|
||||
});
|
||||
worker.on("pagehide", function(){
|
||||
array.remove(workers, this);
|
||||
});
|
||||
worker.on("detach", function(){
|
||||
array.remove(workers, this);
|
||||
});
|
||||
worker.port.on("isPDF", function(blocking){
|
||||
if (prefs.allowPDFCanvas){
|
||||
this.emit("unblock");
|
||||
|
@ -168,7 +157,6 @@
|
|||
}
|
||||
});
|
||||
worker.port.emit("setTranslation", "askForPermission", _("askForPermission"));
|
||||
worker.port.emit("setTranslation", "askForInvisiblePermission", _("askForInvisiblePermission"));
|
||||
checkWorker(worker);
|
||||
},
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue