mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-01-03 18:42:00 +01:00
First implementation
This commit is contained in:
parent
7e0195818b
commit
caba7e33d0
@ -1,11 +1,15 @@
|
|||||||
/* global self, window, console, unsafeWindow, exportFunction */
|
/* global self, window, console, unsafeWindow, exportFunction, cloneInto */
|
||||||
(function(){
|
(function(){
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var blockMode = {
|
var blockMode = {
|
||||||
getContext: {
|
getContext: {
|
||||||
status: "block",
|
status: "block",
|
||||||
askText: "askForPermission",
|
askText: {
|
||||||
|
visible: "askForVisiblePermission",
|
||||||
|
invisible: "askForInvisiblePermission",
|
||||||
|
nocanvas: "askForPermission"
|
||||||
|
},
|
||||||
askStatus: {
|
askStatus: {
|
||||||
askOnce: false,
|
askOnce: false,
|
||||||
alreadyAsked: false,
|
alreadyAsked: false,
|
||||||
@ -14,7 +18,11 @@
|
|||||||
},
|
},
|
||||||
readAPI: {
|
readAPI: {
|
||||||
status: "allow",
|
status: "allow",
|
||||||
askText: "askForReadoutPermission",
|
askText: {
|
||||||
|
visible: "askForVisibleReadoutPermission",
|
||||||
|
invisible: "askForInvisibleReadoutPermission",
|
||||||
|
nocanvas: "askForReadoutPermission"
|
||||||
|
},
|
||||||
askStatus: {
|
askStatus: {
|
||||||
askOnce: false,
|
askOnce: false,
|
||||||
alreadyAsked: false,
|
alreadyAsked: false,
|
||||||
@ -33,6 +41,44 @@
|
|||||||
return bytes;
|
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
|
// changed functions
|
||||||
var changedFunctions = {
|
var changedFunctions = {
|
||||||
getContext: {
|
getContext: {
|
||||||
@ -101,10 +147,13 @@
|
|||||||
status = askStatus.answer;
|
status = askStatus.answer;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
var appearance = canvasAppearance(this);
|
||||||
// console.log("asking");
|
// 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.alreadyAsked = true;
|
||||||
askStatus.answer = status;
|
askStatus.answer = status;
|
||||||
|
|
||||||
|
appearance.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
switch (status){
|
switch (status){
|
||||||
|
@ -153,8 +153,13 @@
|
|||||||
this.emit(blocking, true, prefs.askOnlyOnce);
|
this.emit(blocking, true, prefs.askOnlyOnce);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
worker.port.emit("setTranslation", "askForPermission", _("askForPermission"));
|
["", "Readout"].forEach(function(type){
|
||||||
worker.port.emit("setTranslation", "askForReadoutPermission", _("askForReadoutPermission"));
|
["", "Visible", "Invisible"].forEach(function(visibility){
|
||||||
|
var text = "askFor" + visibility + type + "Permission";
|
||||||
|
worker.port.emit("setTranslation", text, _(text));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
checkWorker(worker);
|
checkWorker(worker);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -23,4 +23,8 @@ 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.
|
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?
|
askForPermission= Wollen Sie <canvas> erlauben?
|
||||||
|
askForVisiblePermission= Wollen Sie das rot umrandete <canvas> erlauben?
|
||||||
|
askForInvisiblePermission= Wollen Sie unsichtbare <canvas> erlauben?
|
||||||
askForReadoutPermission= Wollen Sie das Auslesen von <canvas> erlauben?
|
askForReadoutPermission= Wollen Sie das Auslesen von <canvas> erlauben?
|
||||||
|
askForVisibleReadoutPermission= Wollen Sie das Auslesen des rot umrandeten <canvas> erlauben?
|
||||||
|
askForInvisibleReadoutPermission= Wollen Sie das Auslesen von unsichtbaren <canvas> erlauben?
|
@ -23,4 +23,8 @@ 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.
|
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>?
|
askForPermission= Do you want to allow <canvas>?
|
||||||
|
askForVisiblePermission= Do you want to allow the red bordered <canvas>?
|
||||||
|
askForInvisiblePermission= Do you want to allow invisible <canvas>?
|
||||||
askForReadoutPermission= Do you want to allow <canvas> readout?
|
askForReadoutPermission= Do you want to allow <canvas> readout?
|
||||||
|
askForVisibleReadoutPermission= Do you want to allow the readout of the red bordered <canvas>?
|
||||||
|
askForInvisibleReadoutPermission= Do you want to allow invisible <canvas> readout?
|
Loading…
x
Reference in New Issue
Block a user