diff --git a/canvasblocker.xpi b/canvasblocker.xpi index d00aa05..6ada034 100644 Binary files a/canvasblocker.xpi and b/canvasblocker.xpi differ diff --git a/data/inject.js b/data/inject.js index a45b194..d479bc6 100644 --- a/data/inject.js +++ b/data/inject.js @@ -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; + }); }()); diff --git a/lib/main.js b/lib/main.js index 318e80c..d49e21a 100644 --- a/lib/main.js +++ b/lib/main.js @@ -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); }, }); diff --git a/locale/de-DE.properties b/locale/de-DE.properties index 1cf7ed2..0af4d33 100644 --- a/locale/de-DE.properties +++ b/locale/de-DE.properties @@ -19,8 +19,17 @@ blockMode_options.allow everything= alles erlauben askOnlyOnce_title= Nur einmal nachfragen askOnlyOnce_description= Wenn eine Seite öfters versucht, die -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= 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 erlauben? -askForReadoutPermission= Wollen Sie das Auslesen von erlauben? \ No newline at end of file +askForReadoutPermission= Wollen Sie das Auslesen von erlauben? + +sourceOutput= Aufrufende Datei +stackEntryOutput= {url} Zeile {line} Spalte {column} \ No newline at end of file diff --git a/locale/en-US.properties b/locale/en-US.properties index e989787..267cdac 100644 --- a/locale/en-US.properties +++ b/locale/en-US.properties @@ -19,8 +19,17 @@ blockMode_options.allow everything= allow everything askOnlyOnce_title= Ask only once askOnlyOnce_description= If a page tries to access the -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 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 ? -askForReadoutPermission= Do you want to allow readout? \ No newline at end of file +askForReadoutPermission= Do you want to allow readout? + +sourceOutput= Calling file +stackEntryOutput= {url} line {line} column {column} \ No newline at end of file diff --git a/package.json b/package.json index db6f712..5200844 100644 --- a/package.json +++ b/package.json @@ -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",