From caba7e33d0451260c1c3b0b3bd6c6606e9fa1bf5 Mon Sep 17 00:00:00 2001 From: kkapsner Date: Thu, 4 Dec 2014 23:34:41 +0100 Subject: [PATCH] First implementation --- data/inject.js | 57 ++++++++++++++++++++++++++++++++++++++--- lib/main.js | 9 +++++-- locale/de-DE.properties | 6 ++++- locale/en-US.properties | 6 ++++- 4 files changed, 70 insertions(+), 8 deletions(-) diff --git a/data/inject.js b/data/inject.js index fbb1099..df8b82d 100644 --- a/data/inject.js +++ b/data/inject.js @@ -1,11 +1,15 @@ -/* global self, window, console, unsafeWindow, exportFunction */ +/* global self, window, console, unsafeWindow, exportFunction, cloneInto */ (function(){ "use strict"; var blockMode = { getContext: { status: "block", - askText: "askForPermission", + askText: { + visible: "askForVisiblePermission", + invisible: "askForInvisiblePermission", + nocanvas: "askForPermission" + }, askStatus: { askOnce: false, alreadyAsked: false, @@ -14,7 +18,11 @@ }, readAPI: { status: "allow", - askText: "askForReadoutPermission", + askText: { + visible: "askForVisibleReadoutPermission", + invisible: "askForInvisibleReadoutPermission", + nocanvas: "askForReadoutPermission" + }, askStatus: { askOnce: false, alreadyAsked: false, @@ -33,6 +41,44 @@ return bytes; }()); + // Check canvas appearance + function canvasAppearance(context){ + var oldBorder = false; + var canvas = false; + var visible = false; + if (context){ + if (context.nodeName === "CANVAS"){ + canvas = context; + } + else if ( + context instanceof CanvasRenderingContext2D || + context instanceof WebGLRenderingContext + ){ + canvas = context.canvas; + } + } + if (canvas){ + oldBorder = canvas.style.border; + canvas.style.border = "2px solid red"; + if (canvas.ownerDocument.contains(canvas)){ + canvas.scrollIntoView(); + var rect = canvas.getBoundingClientRect(); + var foundEl = document.elementFromPoint(rect.left + rect.width / 2, rect.top + rect.height / 2); + visible = (foundEl === canvas); + } + } + return { + canvas: canvas, + text: canvas? (visible? "visible": "invisible"): "nocanvas", + visible: visible, + reset: function(){ + if (canvas){ + canvas.style.border = oldBorder; + } + } + }; + } + // changed functions var changedFunctions = { getContext: { @@ -101,10 +147,13 @@ status = askStatus.answer; } else { + var appearance = canvasAppearance(this); // console.log("asking"); - status = window.confirm(_(changedFunction.mode.askText))? "allow": "block"; + status = window.confirm(_(changedFunction.mode.askText[appearance.text]))? "allow": "block"; askStatus.alreadyAsked = true; askStatus.answer = status; + + appearance.reset(); } } switch (status){ diff --git a/lib/main.js b/lib/main.js index 318e80c..81294b4 100644 --- a/lib/main.js +++ b/lib/main.js @@ -153,8 +153,13 @@ this.emit(blocking, true, prefs.askOnlyOnce); } }); - worker.port.emit("setTranslation", "askForPermission", _("askForPermission")); - worker.port.emit("setTranslation", "askForReadoutPermission", _("askForReadoutPermission")); + ["", "Readout"].forEach(function(type){ + ["", "Visible", "Invisible"].forEach(function(visibility){ + var text = "askFor" + visibility + type + "Permission"; + worker.port.emit("setTranslation", text, _(text)); + }); + }); + checkWorker(worker); }, }); diff --git a/locale/de-DE.properties b/locale/de-DE.properties index 1cf7ed2..083c1e4 100644 --- a/locale/de-DE.properties +++ b/locale/de-DE.properties @@ -23,4 +23,8 @@ 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 +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 diff --git a/locale/en-US.properties b/locale/en-US.properties index e989787..0793112 100644 --- a/locale/en-US.properties +++ b/locale/en-US.properties @@ -23,4 +23,8 @@ 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 +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