1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2025-01-03 10:31:54 +01:00

Added preferences to display caller(s)

This commit is contained in:
kkapsner 2014-12-15 18:43:47 +01:00
parent a408a73629
commit 1c0dc233a9
6 changed files with 87 additions and 9 deletions

Binary file not shown.

View File

@ -2,6 +2,9 @@
(function(){
"use strict";
var settings = {
showCallingFile: false
};
var blockMode = {
getContext: {
status: "block",
@ -103,8 +106,8 @@
else {
//console.log("asking");
var msg = _(changedFunction.mode.askText);
if (changedFunction.mode.askText === "askForReadoutPermission"){
var callers = new Error().stack.split('\n');
if (settings.showCallingFile){
var callers = new Error().stack.trim().split("\n");
//console.log(callers);
var findme = callers.shift(); // Remove us from the stack
findme = findme.replace(/(:[0-9]+){1,2}$/, ""); // rm line & column
@ -112,9 +115,15 @@
callers = callers.filter(function(caller){
return caller.search(findme) === -1;
});
msg += "\n\nCaller: " + callers[0];
// maybe show full stack here if some pref
//msg += "\n\nFull stack: \n" + callers.join('\n');
msg += "\n\n" + _("sourceOutput") + ": ";
if (settings.showCompleteCallingStack){
msg += callers.reduce(function(stack, c){
return stack + "\n\t" + _("stackEntryOutput", parseStackEntry(c));
}, "");
}
else{
msg += _("stackEntryOutput", parseStackEntry(callers[0]));
}
}
status = window.confirm(msg) ? "allow": "block";
askStatus.alreadyAsked = true;
@ -140,9 +149,26 @@
);
});
// Stack parsing
function parseStackEntry(entry){
var m = /@(.*):(\d*):(\d*)$/.exec(entry) || ["", entry, "--", "--"];
return {
url: m[1],
line: m[2],
column: m[3],
raw: entry
};
}
// Translation
var _ = function(name){
return _[name] || name;
var _ = function(name, replace){
var str = _[name] || name;
if (replace){
Object.keys(replace).forEach(function(name){
str = str.replace(new RegExp("{" + name + "}", "g"), replace[name]);
});
}
return str;
};
self.port.on("setTranslation", function(name, translation){
_[name] = translation;
@ -198,4 +224,9 @@
blockMode.getContext.status = "allow";
blockMode.readAPI.status = "allow";
});
// settings passthrough
self.port.on("set", function(name, value){
settings[name] = value;
});
}());

View File

@ -73,6 +73,16 @@
updateBlackList();
});
// preferences for injected file
var preferencesForInjected = ["showCallingFile", "showCompleteCallingStack"];
preferencesForInjected.forEach(function(name){
preferences.on(name, function(){
workers.forEach(function(worker){
worker.port.emit("set", name, prefs[name]);
});
});
});
function checkURL(url){
var url = new URL(url);
var mode = "block";
@ -155,6 +165,13 @@
});
worker.port.emit("setTranslation", "askForPermission", _("askForPermission"));
worker.port.emit("setTranslation", "askForReadoutPermission", _("askForReadoutPermission"));
worker.port.emit("setTranslation", "sourceOutput", _("sourceOutput"));
worker.port.emit("setTranslation", "stackEntryOutput", _("stackEntryOutput"));
preferencesForInjected.forEach(function(name){
worker.port.emit("set", name, prefs[name]);
});
checkWorker(worker);
},
});

View File

@ -19,8 +19,17 @@ blockMode_options.allow everything= alles erlauben
askOnlyOnce_title= Nur einmal nachfragen
askOnlyOnce_description= Wenn eine Seite öfters versucht, die <canvas>-API abzurufen, erscheint jedes mal eine Nachfrage. Mit diesem Schalter wird pro Seitenbesuch nur einmal nachgefragt. Bei manchen Seiten kann es trotzdem zu mehrmaligem Nachfragen kommen.
showCallingFile_title= Aufrufende Datei anzeigen
showCallingFile_description=
showCompleteCallingStack_title= Kompletten Aufrufestack anzeigen
showCompleteCallingStack_description=
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 <canvas> erlauben?
askForReadoutPermission= Wollen Sie das Auslesen von <canvas> erlauben?
sourceOutput= Aufrufende Datei
stackEntryOutput= {url} Zeile {line} Spalte {column}

View File

@ -19,8 +19,17 @@ blockMode_options.allow everything= allow everything
askOnlyOnce_title= Ask only once
askOnlyOnce_description= If a page tries to access the <canvas>-API several times a confirm message will appear every time. This switch tries to make only one confirmation. Never the less on some pages there will be more.
showCallingFile_title= Show calling file
showCallingFile_description=
showCompleteCallingStack_title= Display complete calling stack
showCompleteCallingStack_description=
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 <canvas>?
askForReadoutPermission= Do you want to allow <canvas> readout?
sourceOutput= Calling file
stackEntryOutput= {url} line {line} column {column}

View File

@ -62,6 +62,18 @@
"type": "bool",
"value": true
},
{
"name": "showCallingFile",
"title": "Display calling file",
"type": "bool",
"value": false
},
{
"name": "showCompleteCallingStack",
"title": "Display complete calling stack",
"type": "bool",
"value": false
},
{
"name": "allowPDFCanvas",
"title": "Allow canvas in PDFs",