1
0
Fork 0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2025-07-04 04:26:35 +02:00

Separated invisible and visible canvas asking

This commit is contained in:
kkapsner 2014-08-17 23:32:23 +02:00
parent 8098c9177c
commit 430a9226dc
7 changed files with 146 additions and 26 deletions

View file

@ -34,7 +34,9 @@ var pageMod = require("sdk/page-mod");
var preferences = require("sdk/simple-prefs");
var prefs = preferences.prefs;
var {URL} = require("sdk/url");
var _ = require("sdk/l10n").get;
// preferences
var whiteList;
function updateWhiteList(){
whiteList = getDomainRegExpList(prefs.whiteList);
@ -55,6 +57,7 @@ preferences.on("blackList", function(){
workers.forEach(checkWorker);
});
var workers = [];
function detachWorker(worker, workerArray) {
var index = workerArray.indexOf(worker);
@ -83,7 +86,12 @@ function checkWorker(worker){
}
else {
if (prefs.askPermission){
worker.port.emit("ask");
if (prefs.askInvisiblePermission){
worker.port.emit("askInvisible");
}
else {
worker.port.emit("ask");
}
}
else {
worker.port.emit("block");
@ -96,6 +104,7 @@ function checkWorker(worker){
preferences.on("blockAll", function(){
if (prefs.blockAll){
prefs.askPermission = false;
prefs.askInsiviblePermission = false;
}
workers.forEach(checkWorker);
});
@ -103,6 +112,16 @@ preferences.on("askPermission", function(){
if (prefs.askPermission){
prefs.blockAll = false;
}
else {
prefs.askInvisiblePermission = false;
}
workers.forEach(checkWorker);
});
preferences.on("askInvisiblePermission", function(){
if (prefs.askInvisiblePermission){
prefs.askPermission = true;
prefs.blockAll = false;
}
workers.forEach(checkWorker);
});
preferences.on("allowPDFCanvas", function(){
@ -115,12 +134,14 @@ pageMod.PageMod({
contentScriptWhen: "start",
contentScriptFile: self.data.url("inject.js"),
onAttach: function(worker){
checkWorker(worker);
workers.push(worker);
worker.on("detach", function(){
detachWorker(this, workers);
});
worker.port.on("getTranslation", function(name){
worker.port.emit("setTranslation", name, _.apply(null, arguments));
});
worker.port.on("isPDF", function(blocking){
if (prefs.allowPDFCanvas){
worker.port.emit("unblock");
@ -129,5 +150,8 @@ pageMod.PageMod({
worker.port.emit(blocking, true);
}
});
worker.port.emit("setTranslation", "askForPermission", _("askForPermission"));
worker.port.emit("setTranslation", "askForInvisiblePermission", _("askForInvisiblePermission"));
checkWorker(worker);
},
});