diff --git a/canvasblocker.xpi b/canvasblocker.xpi index a8db77f..44c3ce4 100644 Binary files a/canvasblocker.xpi and b/canvasblocker.xpi differ diff --git a/data/inject.js b/data/inject.js index df8b82d..8eb466e 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", @@ -147,12 +150,32 @@ status = askStatus.answer; } else { + //console.log("asking"); var appearance = canvasAppearance(this); - // console.log("asking"); - status = window.confirm(_(changedFunction.mode.askText[appearance.text]))? "allow": "block"; + var msg = _(changedFunction.mode.askText[appearance.text]); + 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 + // Eliminate squashed stack. stack may contain 2+ stacks, but why... + callers = callers.filter(function(caller){ + return caller.search(findme) === -1; + }); + 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; askStatus.answer = status; - + //console.log("asking (done)"); appearance.reset(); } } @@ -174,9 +197,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; @@ -232,4 +272,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 81294b4..36a47ec 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"; @@ -159,6 +169,12 @@ worker.port.emit("setTranslation", text, _(text)); }); }); + 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 083c1e4..85b2e31 100644 --- a/locale/de-DE.properties +++ b/locale/de-DE.properties @@ -19,6 +19,12 @@ 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. @@ -27,4 +33,7 @@ askForVisiblePermission= Wollen Sie das rot umrandete erlauben? askForInvisiblePermission= Wollen Sie unsichtbare erlauben? askForReadoutPermission= Wollen Sie das Auslesen von erlauben? askForVisibleReadoutPermission= Wollen Sie das Auslesen des rot umrandeten erlauben? -askForInvisibleReadoutPermission= Wollen Sie das Auslesen von unsichtbaren erlauben? \ No newline at end of file +askForInvisibleReadoutPermission= Wollen Sie das Auslesen von unsichtbaren 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 0793112..2d1bdb9 100644 --- a/locale/en-US.properties +++ b/locale/en-US.properties @@ -19,6 +19,12 @@ 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. @@ -27,4 +33,7 @@ askForVisiblePermission= Do you want to allow the red bordered ? askForInvisiblePermission= Do you want to allow invisible ? askForReadoutPermission= Do you want to allow readout? askForVisibleReadoutPermission= Do you want to allow the readout of the red bordered ? -askForInvisibleReadoutPermission= Do you want to allow invisible readout? \ No newline at end of file +askForInvisibleReadoutPermission= Do you want to allow invisible 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",