mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2024-12-22 12:50:36 +01:00
Separated invisible and visible canvas asking
This commit is contained in:
parent
8098c9177c
commit
430a9226dc
BIN
AllowIcon.png
Normal file
BIN
AllowIcon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.7 KiB |
BIN
AskIcon.png
Normal file
BIN
AskIcon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.6 KiB |
@ -16,6 +16,7 @@ function block(force){
|
||||
unsafeWindow.HTMLCanvasElement.prototype.getContext = null;
|
||||
}
|
||||
}
|
||||
|
||||
function ask(force){
|
||||
if (force || !checkPDF("ask")){
|
||||
// console.log("ask");
|
||||
@ -28,23 +29,69 @@ function ask(force){
|
||||
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?
|
||||
"Do you want to allow the red bordered <canvas>?":
|
||||
"Do you want to allow an invisibe <canvas>?";
|
||||
var allow = confirm(confirmText);
|
||||
this.style.border = oldBorder;
|
||||
if (allow){
|
||||
this.getContext = this["askFunctionName"];
|
||||
return this["askFunctionName"].apply(this, arguments);
|
||||
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")){
|
||||
// console.log("ask");
|
||||
|
||||
Object.defineProperty(
|
||||
unsafeWindow.HTMLCanvasElement.prototype,
|
||||
askFunctionName,
|
||||
{
|
||||
value: getContext,
|
||||
enumerabe: false
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}.toString().replace(/^function\s*\(\)\s*\{|\}\s*$/g, "").replace(/askFunctionName/g, askFunctionName));
|
||||
);
|
||||
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(){
|
||||
@ -52,8 +99,16 @@ function unblock(){
|
||||
unsafeWindow.HTMLCanvasElement.prototype.getContext = getContext;
|
||||
}
|
||||
|
||||
ask();
|
||||
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);
|
28
lib/main.js
28
lib/main.js
@ -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);
|
||||
},
|
||||
});
|
20
locale/de-DE.properties
Normal file
20
locale/de-DE.properties
Normal file
@ -0,0 +1,20 @@
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
askForPermission= Wollen Sie das rot umrandete <canvas> erlauben?
|
||||
askForInvisiblePermission= Wollen Sie ein verstecktes <canvas> erlauben?
|
20
locale/en-US.properties
Normal file
20
locale/en-US.properties
Normal file
@ -0,0 +1,20 @@
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
askForPermission= Do you want to allow the red bordered <canvas>?
|
||||
askForInvisiblePermission= Do you want to allow an invisibe <canvas>?
|
15
package.json
15
package.json
@ -7,41 +7,42 @@
|
||||
{
|
||||
"name": "whiteList",
|
||||
"title": "White list",
|
||||
"description": "Domains where the <canvas>-API should not be blocked. To add multiple domains seperate them by comma.",
|
||||
"type": "string",
|
||||
"value": "kkapsner.de,^https?://(\\\\w+\\\\.)*google.[a-z]+/maps"
|
||||
},
|
||||
{
|
||||
"name": "blockAll",
|
||||
"title": "Block everything",
|
||||
"description": "If you want to block everything (ignore the white list).",
|
||||
"type": "bool",
|
||||
"value": false
|
||||
},
|
||||
{
|
||||
"name": "blackList",
|
||||
"title": "Black list",
|
||||
"description": "Domains where the <canvas>-API should always be blocked. To add multiple domains seperate them by comma.",
|
||||
"type": "string",
|
||||
"value": ""
|
||||
},
|
||||
{
|
||||
"name": "askPermission",
|
||||
"title": "Ask for permission",
|
||||
"description": "If you want to be asked if you want to block a canvas element if the domain is neither in the white or black list.",
|
||||
"type": "bool",
|
||||
"value": true
|
||||
},
|
||||
{
|
||||
"name": "askInvisiblePermission",
|
||||
"title": "Ask for permission for invisible elements",
|
||||
"type": "bool",
|
||||
"value": false
|
||||
},
|
||||
{
|
||||
"name": "allowPDFCanvas",
|
||||
"title": "Allow canvas in PDFs.",
|
||||
"description": "The native pdf.js uses <canvas> to display the PDF content. If this is unchecked there will lots of annoying ask dialogs.",
|
||||
"title": "Allow canvas in PDFs",
|
||||
"type": "bool",
|
||||
"value": true
|
||||
}
|
||||
],
|
||||
"author": "Korbinian Kapsner",
|
||||
"license": "MPL 2.0",
|
||||
"version": "0.1.2",
|
||||
"version": "0.1.3",
|
||||
"permissions": {"private-browsing": true}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user