1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-05-29 09:28:06 +02: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,40 +1,82 @@
var getContext = unsafeWindow.HTMLCanvasElement.prototype.getContext;
var askFunctionName = Math.random().toString(16);
(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)){
self.port.emit("isPDF", blocking);
return true;
function checkPDF(blocking){
if (document.contentType.match(/\/pdf$/i)){
self.port.emit("isPDF", blocking);
return true;
}
return false;
}
return false;
}
function block(force){
if (force || !checkPDF("block")){
// consoe.log("block");
delete unsafeWindow.HTMLCanvasElement.prototype[askFunctionName];
unsafeWindow.HTMLCanvasElement.prototype.getContext = null;
function block(force){
if (force || !checkPDF("block")){
// consoe.log("block");
delete unsafeWindow.HTMLCanvasElement.prototype[askFunctionName];
unsafeWindow.HTMLCanvasElement.prototype.getContext = null;
}
}
}
function ask(force){
if (force || !checkPDF("ask")){
// console.log("ask");
Object.defineProperty(
unsafeWindow.HTMLCanvasElement.prototype,
askFunctionName,
{
value: getContext,
enumerabe: false
}
);
unsafeWindow.HTMLCanvasElement.prototype.getContext = new unsafeWindow.Function(
function(){
if (this.parentNode){
function askVisible(force){
if (force || !checkPDF("askVisible")){
Object.defineProperty(
unsafeWindow.HTMLCanvasElement.prototype,
askFunctionName,
{
value: getContext,
enumerabe: false
}
);
unsafeWindow.HTMLCanvasElement.prototype.getContext = new unsafeWindow.Function(
function(){
if (this.parentNode){
var oldBorder = this.style.border;
this.style.border = "2px dashed red";
var confirmText = "askForPermission";
var allow = confirm(confirmText);
this.style.border = oldBorder;
if (allow){
this.getContext = this["askFunctionName"];
return this["askFunctionName"].apply(this, arguments);
}
else {
this.getContext = null;
return null;
}
}
else {
return null;
}
}.toString()
.replace(/^function\s*\(\)\s*\{|\}\s*$/g, "")
.replace(/askFunctionName/g, askFunctionName)
.replace(/askForPermission/g, _("askForPermission"))
);
}
}
function askInvisible(force){
if (force || !checkPDF("askInvisible")){
Object.defineProperty(
unsafeWindow.HTMLCanvasElement.prototype,
askFunctionName,
{
value: getContext,
enumerabe: false
}
);
unsafeWindow.HTMLCanvasElement.prototype.getContext = new unsafeWindow.Function(
function(){
var oldBorder = this.style.border;
this.style.border = "2px dashed red";
var confirmText = "askForPermission";
var confirmText =
this.parentNode?
"askForPermission":
"askForInvisiblePermission";
var allow = confirm(confirmText);
this.style.border = oldBorder;
if (allow){
@ -45,70 +87,30 @@ function ask(force){
this.getContext = null;
return null;
}
}
else {
return null;
}
}.toString()
.replace(/^function\s*\(\)\s*\{|\}\s*$/g, "")
.replace(/askFunctionName/g, askFunctionName)
.replace(/askForPermission/g, _("askForPermission"))
);
}.toString()
.replace(/^function\s*\(\)\s*\{|\}\s*$/g, "")
.replace(/askFunctionName/g, askFunctionName)
.replace(/askForPermission/g, _("askForPermission"))
.replace(/askForInvisiblePermission/g, _("askForInvisiblePermission"))
);
}
}
}
function askInvisible(force){
if (force || !checkPDF("askInvisible")){
// console.log("ask");
Object.defineProperty(
unsafeWindow.HTMLCanvasElement.prototype,
askFunctionName,
{
value: getContext,
enumerabe: false
}
);
unsafeWindow.HTMLCanvasElement.prototype.getContext = new unsafeWindow.Function(
function(){
var oldBorder = this.style.border;
this.style.border = "2px dashed red";
var confirmText =
this.parentNode?
"askForPermission":
"askForInvisiblePermission";
var allow = confirm(confirmText);
this.style.border = oldBorder;
if (allow){
this.getContext = this["askFunctionName"];
return this["askFunctionName"].apply(this, arguments);
}
else {
this.getContext = null;
return null;
}
}.toString()
.replace(/^function\s*\(\)\s*\{|\}\s*$/g, "")
.replace(/askFunctionName/g, askFunctionName)
.replace(/askForPermission/g, _("askForPermission"))
.replace(/askForInvisiblePermission/g, _("askForInvisiblePermission"))
);
function unblock(){
// console.log("unblock");
unsafeWindow.HTMLCanvasElement.prototype.getContext = getContext;
}
}
function unblock(){
// console.log("unblock");
unsafeWindow.HTMLCanvasElement.prototype.getContext = getContext;
}
var _ = function(name){
return _[name] || name;
}
self.port.on("setTranslation", function(name, translation){
_[name] = translation;
});
var _ = function(name){
return _[name] || name;
}
self.port.on("setTranslation", function(name, translation){
_[name] = translation;
});
block();
self.port.on("block", block);
self.port.on("ask", ask);
self.port.on("askInvisible", askInvisible);
self.port.on("unblock", unblock);
self.port.on("detach", unblock);
block();
self.port.on("block", block);
self.port.on("askVisible", askVisible);
self.port.on("askInvisible", askInvisible);
self.port.on("unblock", unblock);
self.port.on("detach", unblock);
}());

View File

@ -1,157 +1,162 @@
function getDomainRegExpList(domainList){
return domainList
.split(",")
.map(function(entry){
return entry.replace(/^\s+|\s+$/g, "");
})
.filter(function(entry){
return !!entry.length;
})
.map(function(entry){
var regExp;
var domain = !!entry.match(/^[\w.]+$/);
if (domain){
regExp = new RegExp("(?:^|\\.)" + entry.replace(/([\\\+\*\?\[\^\]\$\(\)\{\}\=\!\|\.])/g, "\\$1") + "\\.?$", "i")
}
else {
regExp = new RegExp(entry, "i");
}
return {
match: function(url){
if (domain){
return url.hostname.match(regExp);
}
else {
return url.href.match(regExp);
}
(function(){
"use strict";
function getDomainRegExpList(domainList){
var list = domainList
.split(",")
.map(function(entry){
return entry.replace(/^\s+|\s+$/g, "");
})
.filter(function(entry){
return !!entry.length;
})
.map(function(entry){
var regExp;
var domain = !!entry.match(/^[\w.]+$/);
if (domain){
regExp = new RegExp("(?:^|\\.)" + entry.replace(/([\\\+\*\?\[\^\]\$\(\)\{\}\=\!\|\.])/g, "\\$1") + "\\.?$", "i")
}
};
});
}
var self = require("sdk/self");
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);
}
updateWhiteList();
preferences.on("whiteList", function(){
updateWhiteList();
workers.forEach(checkWorker);
});
var blackList;
function updateBlackList(){
blackList = getDomainRegExpList(prefs.blackList);
}
updateBlackList();
preferences.on("blackList", function(){
updateBlackList();
workers.forEach(checkWorker);
});
var workers = [];
function detachWorker(worker, workerArray) {
var index = workerArray.indexOf(worker);
if (index != -1){
workerArray.splice(index, 1);
}
}
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){
worker.port.emit("block");
}
else {
var inWhiteList = whiteList.some(function(entry){
return entry.match(url);
else {
regExp = new RegExp(entry, "i");
}
return {
match: function(url){
if (domain){
return url.hostname.match(regExp);
}
else {
return url.href.match(regExp);
}
}
};
});
if (inWhiteList){
worker.port.emit("unblock");
list.match = function(url){
return this.some(function(entry){
return entry.match(url);
})
}
else {
if (prefs.askPermission){
if (prefs.askInvisiblePermission){
worker.port.emit("askInvisible");
}
else {
worker.port.emit("ask");
}
return list;
}
var self = require("sdk/self");
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);
}
updateWhiteList();
preferences.on("whiteList", function(){
updateWhiteList();
workers.forEach(checkWorker);
});
var blackList;
function updateBlackList(){
blackList = getDomainRegExpList(prefs.blackList);
}
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);
switch (prefs.blockMode){
case "blockEverything":
worker.port.emit("block");
break;
case "allowOnlyWhiteList":
if (whiteList.match(url)){
worker.port.emit("unblock");
}
else {
worker.port.emit("block");
}
}
break;
case "askVisible":
if (whiteList.match(url)){
worker.port.emit("unblock");
}
else if (blackList.match(url)){
worker.port.emit("block");
}
else {
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.");
}
}
}
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 {
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(){
workers.forEach(checkWorker);
});
pageMod.PageMod({
include: "*",
contentScriptWhen: "start",
contentScriptFile: self.data.url("inject.js"),
onAttach: function(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");
}
else {
worker.port.emit(blocking, true);
}
});
worker.port.emit("setTranslation", "askForPermission", _("askForPermission"));
worker.port.emit("setTranslation", "askForInvisiblePermission", _("askForInvisiblePermission"));
checkWorker(worker);
},
});
pageMod.PageMod({
include: "*",
contentScriptWhen: "start",
contentScriptFile: self.data.url("inject.js"),
onAttach: function(worker){
workers.push(worker);
worker.on("detach", function(){
detachWorker(this, workers);
});
worker.port.on("isPDF", function(blocking){
if (prefs.allowPDFCanvas){
worker.port.emit("unblock");
}
else {
worker.port.emit(blocking, true);
}
});
worker.port.emit("setTranslation", "askForPermission", _("askForPermission"));
worker.port.emit("setTranslation", "askForInvisiblePermission", _("askForInvisiblePermission"));
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": "askInvisiblePermission",
"title": "Ask for permission for invisible elements",
"type": "bool",
"value": false
"name": "blockMode",
"title": "block mode",
"type": "menulist",
"value": "askVisible",
"options": [
{
"value": "blockEverything",
"label": "block everything"
},
{
"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",