mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2024-12-22 12:50:36 +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(){
|
||||
"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){
|
||||
|
@ -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);
|
||||
},
|
||||
});
|
||||
|
@ -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.
|
||||
|
||||
askForPermission= Wollen Sie <canvas> erlauben?
|
||||
askForReadoutPermission= Wollen Sie das Auslesen von <canvas> erlauben?
|
||||
askForVisiblePermission= Wollen Sie das rot umrandete <canvas> erlauben?
|
||||
askForInvisiblePermission= Wollen Sie unsichtbare <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.
|
||||
|
||||
askForPermission= Do you want to allow <canvas>?
|
||||
askForReadoutPermission= Do you want to allow <canvas> readout?
|
||||
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?
|
||||
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