diff --git a/AllowIcon.png b/AllowIcon.png new file mode 100644 index 0000000..dec1c1d Binary files /dev/null and b/AllowIcon.png differ diff --git a/AskIcon.png b/AskIcon.png new file mode 100644 index 0000000..c929448 Binary files /dev/null and b/AskIcon.png differ diff --git a/data/inject.js b/data/inject.js index 0c4cd8b..8056e68 100644 --- a/data/inject.js +++ b/data/inject.js @@ -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 ?": - "Do you want to allow an invisibe ?"; - 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); \ No newline at end of file diff --git a/lib/main.js b/lib/main.js index 2f2b1cb..a946fe5 100644 --- a/lib/main.js +++ b/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); }, }); \ No newline at end of file diff --git a/locale/de-DE.properties b/locale/de-DE.properties new file mode 100644 index 0000000..377dacb --- /dev/null +++ b/locale/de-DE.properties @@ -0,0 +1,20 @@ +whilteList_title= Whitelist +whiteList_description= Domänen oder URLs, die die -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 -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 -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 -Element blockiert werden soll oder nicht, wenn die Domäne oder URL weder auf der Whitelist noch auf der Blacklist steht. + +allowPDFCanvas_title= in PDFs erlauben +allowPDFCanvas_description= Die native pdf.js verwendet 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 erlauben? +askForInvisiblePermission= Wollen Sie ein verstecktes erlauben? \ No newline at end of file diff --git a/locale/en-US.properties b/locale/en-US.properties new file mode 100644 index 0000000..c876eb0 --- /dev/null +++ b/locale/en-US.properties @@ -0,0 +1,20 @@ +whilteList_title= White list +whiteList_description= Domains or URLs where the -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 -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 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 ? +askForInvisiblePermission= Do you want to allow an invisibe ? \ No newline at end of file diff --git a/package.json b/package.json index 4066943..bab5f49 100644 --- a/package.json +++ b/package.json @@ -7,41 +7,42 @@ { "name": "whiteList", "title": "White list", - "description": "Domains where the -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 -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 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} }