1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2025-01-03 02:21:53 +01:00

Changed settings

This commit is contained in:
kkapsner 2014-08-20 10:21:38 +02:00
parent 430a9226dc
commit 40d059311a
5 changed files with 292 additions and 269 deletions

View File

@ -1,8 +1,11 @@
(function(){
"use strict";
var getContext = unsafeWindow.HTMLCanvasElement.prototype.getContext;
var askFunctionName = Math.random().toString(16);
function checkPDF(blocking){
if (unsafeWindow.document.contentType.match(/\/pdf$/i)){
if (document.contentType.match(/\/pdf$/i)){
self.port.emit("isPDF", blocking);
return true;
}
@ -17,9 +20,8 @@ function block(force){
}
}
function ask(force){
if (force || !checkPDF("ask")){
// console.log("ask");
function askVisible(force){
if (force || !checkPDF("askVisible")){
Object.defineProperty(
unsafeWindow.HTMLCanvasElement.prototype,
@ -58,7 +60,6 @@ function ask(force){
}
function askInvisible(force){
if (force || !checkPDF("askInvisible")){
// console.log("ask");
Object.defineProperty(
unsafeWindow.HTMLCanvasElement.prototype,
@ -108,7 +109,8 @@ self.port.on("setTranslation", function(name, translation){
block();
self.port.on("block", block);
self.port.on("ask", ask);
self.port.on("askVisible", askVisible);
self.port.on("askInvisible", askInvisible);
self.port.on("unblock", unblock);
self.port.on("detach", unblock);
}());

View File

@ -1,5 +1,8 @@
(function(){
"use strict";
function getDomainRegExpList(domainList){
return domainList
var list = domainList
.split(",")
.map(function(entry){
return entry.replace(/^\s+|\s+$/g, "");
@ -27,6 +30,14 @@ function getDomainRegExpList(domainList){
}
};
});
list.match = function(url){
return this.some(function(entry){
return entry.match(url);
})
}
return list;
}
var self = require("sdk/self");
@ -58,6 +69,12 @@ preferences.on("blackList", function(){
});
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);
@ -66,67 +83,56 @@ function detachWorker(worker, workerArray) {
}
}
function checkWorker(worker){
if (prefs.blockAll){
worker.port.emit("block");
}
else {
var url = new URL(worker.url);
var inBlackList = blackList.some(function(entry){
return entry.match(url);
});
if (inBlackList){
switch (prefs.blockMode){
case "blockEverything":
worker.port.emit("block");
}
else {
var inWhiteList = whiteList.some(function(entry){
return entry.match(url);
});
if (inWhiteList){
break;
case "allowOnlyWhiteList":
if (whiteList.match(url)){
worker.port.emit("unblock");
}
else {
if (prefs.askPermission){
if (prefs.askInvisiblePermission){
worker.port.emit("askInvisible");
}
else {
worker.port.emit("ask");
}
}
else {
worker.port.emit("block");
}
break;
case "askVisible":
if (whiteList.match(url)){
worker.port.emit("unblock");
}
}
}
}
preferences.on("blockAll", function(){
if (prefs.blockAll){
prefs.askPermission = false;
prefs.askInsiviblePermission = false;
}
workers.forEach(checkWorker);
});
preferences.on("askPermission", function(){
if (prefs.askPermission){
prefs.blockAll = false;
else if (blackList.match(url)){
worker.port.emit("block");
}
else {
prefs.askInvisiblePermission = false;
worker.port.emit("askVisible");
}
break;
case "askInvisible":
if (whiteList.match(url)){
worker.port.emit("unblock");
}
else if (blackList.match(url)){
worker.port.emit("block");
}
else {
worker.port.emit("askInvisible");
}
break;
case "blockOnlyBlackList":
if (blackList.match(url)){
worker.port.emit("block");
}
else {
worker.port.emit("unblock");
}
break;
case "allowEverything":
worker.port.emit("unblock");
break;
default:
console.log("Unknown blocking mode.");
}
workers.forEach(checkWorker);
});
preferences.on("askInvisiblePermission", function(){
if (prefs.askInvisiblePermission){
prefs.askPermission = true;
prefs.blockAll = false;
}
workers.forEach(checkWorker);
});
preferences.on("allowPDFCanvas", function(){
workers.forEach(checkWorker);
});
pageMod.PageMod({
@ -139,9 +145,6 @@ pageMod.PageMod({
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");
@ -155,3 +158,5 @@ pageMod.PageMod({
checkWorker(worker);
},
});
}());

View File

@ -1,17 +1,18 @@
whilteList_title= Whitelist
whiteList_description= Domänen oder URLs, die die <canvas>-API verwenden dürfen. Mehrere Einträge müssen durch ein Komma getrennt weren.
blockAll_title= Alles blockieren
blockAll_description= Ob immer alles blockiert werden soll (ignoriert die Whitelist).
blackList_title= Blacklist
blackList_description= Domänen oder URLs, die die <canvas>-API niemals verwenden dürfen. Mehrere Einträge müssen durch ein Komma getrennt weren.
askPermission_title= Um Erlaubnis fragen
askPermission_description= Ob man gefragt werden soll, ob ein sichtbares <canvas>-Element blockiert werden soll oder nicht, wenn die Domäne oder URL weder auf der Whitelist noch auf der Blacklist steht.
blockMode_title= Blockiermodus
blockMode_description=
askInvisiblePermission_title= Bei verstecken Elementen um Erlaubnis fragen
askInvisiblePermission_description= Ob man gefragt werden soll, ob ein verstecktes <canvas>-Element blockiert werden soll oder nicht, wenn die Domäne oder URL weder auf der Whitelist noch auf der Blacklist steht.
blockMode_options.block everything= alles blockieren
blockMode_options.allow only white list= nur Einträge der Whitelist erlauben
blockMode_options.ask for permission for visible <canvas>= bei sichtbaren <canvas> um Erlaubnis fragen
blockMode_options.ask for permision for invisible <canvas>= bei unsichtbaren <canvas> um Erlaubnis fragen
blockMode_options.block only black list= nur Einträge der Blacklist blockieren
blockMode_options.allow everything= alles erlauben
allowPDFCanvas_title= <canvas> in PDFs erlauben
allowPDFCanvas_description= Die native pdf.js verwendet <canvas> um den Inhalt von PDFs anzuzeigen. Wenn dies nicht markiert ist, werden viele Nachfragedialoge erscheinen oder die PDF Ansicht nicht funktionieren.

View File

@ -1,17 +1,18 @@
whilteList_title= White list
whiteList_description= Domains or URLs where the <canvas>-API should not be blocked. To add multiple entries seperate them by comma.
blockAll_title= Block everything
blockAll_description= If you want to block everything (ignore the white list).
blackList_title= Black list
blackList_description= Domains or URLs where the <canvas>-API should always be blocked. To add multiple entries seperate them by comma.
askPermission_title= Ask for permission
askPermission_description= If you want to be asked if you want to block a visible canvas element if the domain or URL is neither in the white or black list.
blockMode_title= Block mode
blockMode_description=
askInvisiblePermission_title= Ask for permission for invisible elements
askInvisiblePermission_description= If you want to be asked if you want to block an invisible canvas element if the domain or URL is neither in the white or black list.
blockMode_options.block everything= block everything
blockMode_options.allow only white list= allow only white list
blockMode_options.ask for permission for visible <canvas>= ask for permission for visible <canvas>
blockMode_options.ask for permision for invisible <canvas>= ask for permision for invisible <canvas>
blockMode_options.block only black list= block only black list
blockMode_options.allow everything= allow everything
allowPDFCanvas_title= Allow canvas in PDFs
allowPDFCanvas_description= The native pdf.js uses <canvas> to display the PDF content. If this is unchecked there will lots of annoying ask dialogs or the PDF display will not work.

View File

@ -10,12 +10,6 @@
"type": "string",
"value": "kkapsner.de,^https?://(\\\\w+\\\\.)*google.[a-z]+/maps"
},
{
"name": "blockAll",
"title": "Block everything",
"type": "bool",
"value": false
},
{
"name": "blackList",
"title": "Black list",
@ -23,16 +17,36 @@
"value": ""
},
{
"name": "askPermission",
"title": "Ask for permission",
"type": "bool",
"value": true
"name": "blockMode",
"title": "block mode",
"type": "menulist",
"value": "askVisible",
"options": [
{
"value": "blockEverything",
"label": "block everything"
},
{
"name": "askInvisiblePermission",
"title": "Ask for permission for invisible elements",
"type": "bool",
"value": false
"value": "allowOnlyWhiteList",
"label": "allow only white list"
},
{
"value": "askVisible",
"label": "ask for permission for visible <canvas>"
},
{
"value": "askInvisible",
"label": "ask for permision for invisible <canvas>"
},
{
"value": "blockOnlyBlackList",
"label": "block only black list"
},
{
"value": "allowEverything",
"label": "allow everything"
}
]
},
{
"name": "allowPDFCanvas",