mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-01-03 02:21:53 +01:00
Changed settings
This commit is contained in:
parent
430a9226dc
commit
40d059311a
@ -1,25 +1,27 @@
|
||||
var getContext = unsafeWindow.HTMLCanvasElement.prototype.getContext;
|
||||
var askFunctionName = Math.random().toString(16);
|
||||
(function(){
|
||||
"use strict";
|
||||
|
||||
function checkPDF(blocking){
|
||||
if (unsafeWindow.document.contentType.match(/\/pdf$/i)){
|
||||
var getContext = unsafeWindow.HTMLCanvasElement.prototype.getContext;
|
||||
var askFunctionName = Math.random().toString(16);
|
||||
|
||||
function checkPDF(blocking){
|
||||
if (document.contentType.match(/\/pdf$/i)){
|
||||
self.port.emit("isPDF", blocking);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function block(force){
|
||||
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");
|
||||
function askVisible(force){
|
||||
if (force || !checkPDF("askVisible")){
|
||||
|
||||
Object.defineProperty(
|
||||
unsafeWindow.HTMLCanvasElement.prototype,
|
||||
@ -55,10 +57,9 @@ function ask(force){
|
||||
.replace(/askForPermission/g, _("askForPermission"))
|
||||
);
|
||||
}
|
||||
}
|
||||
function askInvisible(force){
|
||||
}
|
||||
function askInvisible(force){
|
||||
if (force || !checkPDF("askInvisible")){
|
||||
// console.log("ask");
|
||||
|
||||
Object.defineProperty(
|
||||
unsafeWindow.HTMLCanvasElement.prototype,
|
||||
@ -93,22 +94,23 @@ function askInvisible(force){
|
||||
.replace(/askForInvisiblePermission/g, _("askForInvisiblePermission"))
|
||||
);
|
||||
}
|
||||
}
|
||||
function unblock(){
|
||||
}
|
||||
function unblock(){
|
||||
// console.log("unblock");
|
||||
unsafeWindow.HTMLCanvasElement.prototype.getContext = getContext;
|
||||
}
|
||||
}
|
||||
|
||||
var _ = function(name){
|
||||
var _ = function(name){
|
||||
return _[name] || name;
|
||||
}
|
||||
self.port.on("setTranslation", function(name, translation){
|
||||
}
|
||||
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);
|
||||
}());
|
163
lib/main.js
163
lib/main.js
@ -1,5 +1,8 @@
|
||||
function getDomainRegExpList(domainList){
|
||||
return domainList
|
||||
(function(){
|
||||
"use strict";
|
||||
|
||||
function getDomainRegExpList(domainList){
|
||||
var list = domainList
|
||||
.split(",")
|
||||
.map(function(entry){
|
||||
return entry.replace(/^\s+|\s+$/g, "");
|
||||
@ -27,109 +30,112 @@ function getDomainRegExpList(domainList){
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
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;
|
||||
list.match = function(url){
|
||||
return this.some(function(entry){
|
||||
return entry.match(url);
|
||||
})
|
||||
}
|
||||
|
||||
// preferences
|
||||
var whiteList;
|
||||
function updateWhiteList(){
|
||||
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();
|
||||
preferences.on("whiteList", function(){
|
||||
updateWhiteList();
|
||||
workers.forEach(checkWorker);
|
||||
});
|
||||
});
|
||||
|
||||
var blackList;
|
||||
function updateBlackList(){
|
||||
var blackList;
|
||||
function updateBlackList(){
|
||||
blackList = getDomainRegExpList(prefs.blackList);
|
||||
}
|
||||
updateBlackList();
|
||||
preferences.on("blackList", function(){
|
||||
}
|
||||
updateBlackList();
|
||||
preferences.on("blackList", function(){
|
||||
updateBlackList();
|
||||
workers.forEach(checkWorker);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
var workers = [];
|
||||
function detachWorker(worker, workerArray) {
|
||||
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){
|
||||
if (prefs.blockAll){
|
||||
worker.port.emit("block");
|
||||
}
|
||||
else {
|
||||
function checkWorker(worker){
|
||||
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({
|
||||
pageMod.PageMod({
|
||||
include: "*",
|
||||
contentScriptWhen: "start",
|
||||
contentScriptFile: self.data.url("inject.js"),
|
||||
@ -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");
|
||||
@ -154,4 +157,6 @@ pageMod.PageMod({
|
||||
worker.port.emit("setTranslation", "askForInvisiblePermission", _("askForInvisiblePermission"));
|
||||
checkWorker(worker);
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
@ -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.
|
||||
|
@ -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.
|
||||
|
42
package.json
42
package.json
@ -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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user