mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2024-12-22 21:00:23 +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;
|
unsafeWindow.HTMLCanvasElement.prototype.getContext = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function ask(force){
|
function ask(force){
|
||||||
if (force || !checkPDF("ask")){
|
if (force || !checkPDF("ask")){
|
||||||
// console.log("ask");
|
// console.log("ask");
|
||||||
@ -28,13 +29,12 @@ function ask(force){
|
|||||||
enumerabe: false
|
enumerabe: false
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
unsafeWindow.HTMLCanvasElement.prototype.getContext = new unsafeWindow.Function(function(){
|
unsafeWindow.HTMLCanvasElement.prototype.getContext = new unsafeWindow.Function(
|
||||||
|
function(){
|
||||||
|
if (this.parentNode){
|
||||||
var oldBorder = this.style.border;
|
var oldBorder = this.style.border;
|
||||||
this.style.border = "2px dashed red";
|
this.style.border = "2px dashed red";
|
||||||
var confirmText =
|
var confirmText = "askForPermission";
|
||||||
this.parentNode?
|
|
||||||
"Do you want to allow the red bordered <canvas>?":
|
|
||||||
"Do you want to allow an invisibe <canvas>?";
|
|
||||||
var allow = confirm(confirmText);
|
var allow = confirm(confirmText);
|
||||||
this.style.border = oldBorder;
|
this.style.border = oldBorder;
|
||||||
if (allow){
|
if (allow){
|
||||||
@ -42,9 +42,56 @@ function ask(force){
|
|||||||
return this["askFunctionName"].apply(this, arguments);
|
return this["askFunctionName"].apply(this, arguments);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
this.getContext = null;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}.toString().replace(/^function\s*\(\)\s*\{|\}\s*$/g, "").replace(/askFunctionName/g, askFunctionName));
|
}
|
||||||
|
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
|
||||||
|
}
|
||||||
|
);
|
||||||
|
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(){
|
function unblock(){
|
||||||
@ -52,8 +99,16 @@ function unblock(){
|
|||||||
unsafeWindow.HTMLCanvasElement.prototype.getContext = getContext;
|
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("block", block);
|
||||||
self.port.on("ask", ask);
|
self.port.on("ask", ask);
|
||||||
|
self.port.on("askInvisible", askInvisible);
|
||||||
self.port.on("unblock", unblock);
|
self.port.on("unblock", unblock);
|
||||||
self.port.on("detach", unblock);
|
self.port.on("detach", unblock);
|
26
lib/main.js
26
lib/main.js
@ -34,7 +34,9 @@ var pageMod = require("sdk/page-mod");
|
|||||||
var preferences = require("sdk/simple-prefs");
|
var preferences = require("sdk/simple-prefs");
|
||||||
var prefs = preferences.prefs;
|
var prefs = preferences.prefs;
|
||||||
var {URL} = require("sdk/url");
|
var {URL} = require("sdk/url");
|
||||||
|
var _ = require("sdk/l10n").get;
|
||||||
|
|
||||||
|
// preferences
|
||||||
var whiteList;
|
var whiteList;
|
||||||
function updateWhiteList(){
|
function updateWhiteList(){
|
||||||
whiteList = getDomainRegExpList(prefs.whiteList);
|
whiteList = getDomainRegExpList(prefs.whiteList);
|
||||||
@ -55,6 +57,7 @@ preferences.on("blackList", function(){
|
|||||||
workers.forEach(checkWorker);
|
workers.forEach(checkWorker);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
var workers = [];
|
var workers = [];
|
||||||
function detachWorker(worker, workerArray) {
|
function detachWorker(worker, workerArray) {
|
||||||
var index = workerArray.indexOf(worker);
|
var index = workerArray.indexOf(worker);
|
||||||
@ -83,8 +86,13 @@ function checkWorker(worker){
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (prefs.askPermission){
|
if (prefs.askPermission){
|
||||||
|
if (prefs.askInvisiblePermission){
|
||||||
|
worker.port.emit("askInvisible");
|
||||||
|
}
|
||||||
|
else {
|
||||||
worker.port.emit("ask");
|
worker.port.emit("ask");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
worker.port.emit("block");
|
worker.port.emit("block");
|
||||||
}
|
}
|
||||||
@ -96,6 +104,7 @@ function checkWorker(worker){
|
|||||||
preferences.on("blockAll", function(){
|
preferences.on("blockAll", function(){
|
||||||
if (prefs.blockAll){
|
if (prefs.blockAll){
|
||||||
prefs.askPermission = false;
|
prefs.askPermission = false;
|
||||||
|
prefs.askInsiviblePermission = false;
|
||||||
}
|
}
|
||||||
workers.forEach(checkWorker);
|
workers.forEach(checkWorker);
|
||||||
});
|
});
|
||||||
@ -103,6 +112,16 @@ preferences.on("askPermission", function(){
|
|||||||
if (prefs.askPermission){
|
if (prefs.askPermission){
|
||||||
prefs.blockAll = false;
|
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);
|
workers.forEach(checkWorker);
|
||||||
});
|
});
|
||||||
preferences.on("allowPDFCanvas", function(){
|
preferences.on("allowPDFCanvas", function(){
|
||||||
@ -115,12 +134,14 @@ pageMod.PageMod({
|
|||||||
contentScriptWhen: "start",
|
contentScriptWhen: "start",
|
||||||
contentScriptFile: self.data.url("inject.js"),
|
contentScriptFile: self.data.url("inject.js"),
|
||||||
onAttach: function(worker){
|
onAttach: function(worker){
|
||||||
checkWorker(worker);
|
|
||||||
|
|
||||||
workers.push(worker);
|
workers.push(worker);
|
||||||
worker.on("detach", function(){
|
worker.on("detach", function(){
|
||||||
detachWorker(this, workers);
|
detachWorker(this, workers);
|
||||||
});
|
});
|
||||||
|
worker.port.on("getTranslation", function(name){
|
||||||
|
worker.port.emit("setTranslation", name, _.apply(null, arguments));
|
||||||
|
});
|
||||||
worker.port.on("isPDF", function(blocking){
|
worker.port.on("isPDF", function(blocking){
|
||||||
if (prefs.allowPDFCanvas){
|
if (prefs.allowPDFCanvas){
|
||||||
worker.port.emit("unblock");
|
worker.port.emit("unblock");
|
||||||
@ -129,5 +150,8 @@ pageMod.PageMod({
|
|||||||
worker.port.emit(blocking, true);
|
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",
|
"name": "whiteList",
|
||||||
"title": "White list",
|
"title": "White list",
|
||||||
"description": "Domains where the <canvas>-API should not be blocked. To add multiple domains seperate them by comma.",
|
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"value": "kkapsner.de,^https?://(\\\\w+\\\\.)*google.[a-z]+/maps"
|
"value": "kkapsner.de,^https?://(\\\\w+\\\\.)*google.[a-z]+/maps"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "blockAll",
|
"name": "blockAll",
|
||||||
"title": "Block everything",
|
"title": "Block everything",
|
||||||
"description": "If you want to block everything (ignore the white list).",
|
|
||||||
"type": "bool",
|
"type": "bool",
|
||||||
"value": false
|
"value": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "blackList",
|
"name": "blackList",
|
||||||
"title": "Black list",
|
"title": "Black list",
|
||||||
"description": "Domains where the <canvas>-API should always be blocked. To add multiple domains seperate them by comma.",
|
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"value": ""
|
"value": ""
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "askPermission",
|
"name": "askPermission",
|
||||||
"title": "Ask for permission",
|
"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",
|
"type": "bool",
|
||||||
"value": true
|
"value": true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "askInvisiblePermission",
|
||||||
|
"title": "Ask for permission for invisible elements",
|
||||||
|
"type": "bool",
|
||||||
|
"value": false
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "allowPDFCanvas",
|
"name": "allowPDFCanvas",
|
||||||
"title": "Allow canvas in PDFs.",
|
"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.",
|
|
||||||
"type": "bool",
|
"type": "bool",
|
||||||
"value": true
|
"value": true
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"author": "Korbinian Kapsner",
|
"author": "Korbinian Kapsner",
|
||||||
"license": "MPL 2.0",
|
"license": "MPL 2.0",
|
||||||
"version": "0.1.2",
|
"version": "0.1.3",
|
||||||
"permissions": {"private-browsing": true}
|
"permissions": {"private-browsing": true}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user