mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2024-12-22 12:50:36 +01:00
Added askReadout
This commit is contained in:
parent
23b5d7672c
commit
7da2a94030
Binary file not shown.
192
data/inject.js
192
data/inject.js
@ -1,4 +1,4 @@
|
||||
/* global self, window, console, unsafeWindow */
|
||||
/* global self, window, console, unsafeWindow, exportFunction */
|
||||
(function(){
|
||||
"use strict";
|
||||
|
||||
@ -12,7 +12,12 @@
|
||||
}
|
||||
},
|
||||
readAPI: {
|
||||
status: "allow"
|
||||
status: "allow",
|
||||
askStatus: {
|
||||
askOnce: false,
|
||||
alreadyAsked: false,
|
||||
answer: null
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -62,108 +67,86 @@
|
||||
return bytes;
|
||||
}());
|
||||
|
||||
var originalToDataURL = unsafeWindow.HTMLCanvasElement.prototype.toDataURL;
|
||||
Object.defineProperty(
|
||||
unsafeWindow.HTMLCanvasElement.prototype,
|
||||
"toDataURL",
|
||||
{
|
||||
enumerable: true,
|
||||
configureable: false,
|
||||
get: exportFunction(function(){
|
||||
switch (blockMode.readAPI.status){
|
||||
case "allow":
|
||||
return originalToDataURL;
|
||||
case "block":
|
||||
default:
|
||||
return exportFunction(
|
||||
function(){
|
||||
var type = arguments[0] || "image/png";
|
||||
return "data:" + type + ";base64," + btoa(randomImage);
|
||||
},
|
||||
unsafeWindow
|
||||
);
|
||||
// Readout API blocking
|
||||
var fakeFunctions = {
|
||||
toDataURL: {
|
||||
object: unsafeWindow.HTMLCanvasElement,
|
||||
func: function(){
|
||||
var type = arguments[0] || "image/png";
|
||||
return "data:" + type + ";base64," + btoa(randomImage);
|
||||
}
|
||||
},
|
||||
toBlob: {
|
||||
object: unsafeWindow.HTMLCanvasElement,
|
||||
func: function(callback){
|
||||
var type = arguments[0] || "image/png";
|
||||
var blob = new window.Blob(randomImage, {type: type});
|
||||
callback(blob);
|
||||
},
|
||||
exportOptions: {allowCallbacks: true}
|
||||
},
|
||||
mozGetAsFile: {
|
||||
object: unsafeWindow.HTMLCanvasElement,
|
||||
func: undef
|
||||
},
|
||||
getImageData: {
|
||||
object: unsafeWindow.CanvasRenderingContext2D,
|
||||
func: function(sx, sy, sw, sh){
|
||||
var imageData = new window.ImageData(sw, sh);
|
||||
var l = sw * sh * 4;
|
||||
for (var i = 0; i < l; i += 1){
|
||||
imageData.data[i] = Math.floor(
|
||||
Math.random() * 256
|
||||
);
|
||||
}
|
||||
}, unsafeWindow)
|
||||
return imageData;
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
var originalToBlob = unsafeWindow.HTMLCanvasElement.prototype.toBlob;
|
||||
Object.defineProperty(
|
||||
unsafeWindow.HTMLCanvasElement.prototype,
|
||||
"toBlob",
|
||||
{
|
||||
enumerable: true,
|
||||
configureable: false,
|
||||
get: exportFunction(function(){
|
||||
switch (blockMode.readAPI.status){
|
||||
case "allow":
|
||||
return originalToBlob;
|
||||
case "block":
|
||||
default:
|
||||
return exportFunction(
|
||||
function(callback){
|
||||
var type = arguments[0] || "image/png";
|
||||
var blob = new window.Blob(randomImage, {type: type});
|
||||
callback(blob);
|
||||
},
|
||||
unsafeWindow,
|
||||
{allowCallbacks: true}
|
||||
);
|
||||
}
|
||||
}, unsafeWindow)
|
||||
}
|
||||
);
|
||||
|
||||
var originalMozGetAsFile = unsafeWindow.HTMLCanvasElement.prototype.mozGetAsFile;
|
||||
Object.defineProperty(
|
||||
unsafeWindow.HTMLCanvasElement.prototype,
|
||||
"mozGetAsFile",
|
||||
{
|
||||
enumerable: true,
|
||||
configureable: false,
|
||||
get: exportFunction(function(){
|
||||
switch (blockMode.readAPI.status){
|
||||
case "allow":
|
||||
return originalMozGetAsFile;
|
||||
case "block":
|
||||
default:
|
||||
undef
|
||||
}
|
||||
}, unsafeWindow)
|
||||
}
|
||||
);
|
||||
|
||||
var originalGetImageData = unsafeWindow.CanvasRenderingContext2D.prototype.getImageData;
|
||||
Object.defineProperty(
|
||||
unsafeWindow.CanvasRenderingContext2D.prototype,
|
||||
"getImageData",
|
||||
{
|
||||
enumerable: true,
|
||||
configureable: false,
|
||||
get: exportFunction(function(){
|
||||
switch (blockMode.readAPI.status){
|
||||
case "allow":
|
||||
return originalGetImageData;
|
||||
case "block":
|
||||
default:
|
||||
return exportFunction(
|
||||
function(sx, sy, sw, sh){
|
||||
var imageData = new window.ImageData(sw, sh);
|
||||
var l = sw * sh * 4;
|
||||
for (var i = 0; i < l; i += 1){
|
||||
imageData.data[i] = Math.floor(
|
||||
Math.random() * 256
|
||||
);
|
||||
}
|
||||
return imageData;
|
||||
},
|
||||
unsafeWindow
|
||||
);
|
||||
}
|
||||
}, unsafeWindow)
|
||||
}
|
||||
);
|
||||
Object.keys(fakeFunctions).forEach(function(name){
|
||||
var fakeFunction = fakeFunctions[name];
|
||||
var original = fakeFunction.object.prototype[name];
|
||||
Object.defineProperty(
|
||||
fakeFunction.object.prototype,
|
||||
name,
|
||||
{
|
||||
enumerable: true,
|
||||
configureable: false,
|
||||
get: exportFunction(function(){
|
||||
var status = blockMode.readAPI.status;
|
||||
if (status === "ask"){
|
||||
var askStatus = blockMode.readAPI.askStatus;
|
||||
var allow;
|
||||
if (askStatus.askOnce && askStatus.alreadyAsked){
|
||||
// console.log("already asked");
|
||||
allow = askStatus.answer;
|
||||
}
|
||||
else {
|
||||
// console.log("asking");
|
||||
allow = window.confirm(_("askForReadoutPermission"));
|
||||
askStatus.alreadyAsked = true;
|
||||
askStatus.answer = allow;
|
||||
}
|
||||
status = allow? "allow": "block";
|
||||
}
|
||||
switch (status){
|
||||
case "allow":
|
||||
return original;
|
||||
case "block":
|
||||
default:
|
||||
return exportFunction(
|
||||
fakeFunction.func,
|
||||
unsafeWindow,
|
||||
fakeFunction.exportOptions
|
||||
);
|
||||
}
|
||||
}, unsafeWindow)
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
// Translation
|
||||
var _ = function(name){
|
||||
return _[name] || name;
|
||||
};
|
||||
@ -171,6 +154,8 @@
|
||||
_[name] = translation;
|
||||
});
|
||||
|
||||
// Communication with main.js
|
||||
|
||||
function checkPDF(blocking){
|
||||
if (document.contentType.match(/\/pdf$/i)){
|
||||
self.port.emit("isPDF", blocking);
|
||||
@ -198,6 +183,13 @@
|
||||
blockMode.readAPI.status = "block";
|
||||
}
|
||||
});
|
||||
self.port.on("askReadout", function(force, askOnce){
|
||||
if (force || !checkPDF("askReadout")){
|
||||
blockMode.getContext.status = "allow";
|
||||
blockMode.readAPI.status = "ask";
|
||||
blockMode.readAPI.askStatus.askOnce = askOnce;
|
||||
}
|
||||
});
|
||||
self.port.on("unblock", function(){
|
||||
blockMode.getContext.status = "allow";
|
||||
blockMode.readAPI.status = "allow";
|
||||
|
12
lib/main.js
12
lib/main.js
@ -109,6 +109,17 @@
|
||||
mode = "blockReadout";
|
||||
}
|
||||
break;
|
||||
case "askReadout":
|
||||
if (whiteList.match(url)){
|
||||
mode = "unblock";
|
||||
}
|
||||
else if (blackList.match(url)){
|
||||
mode = "block";
|
||||
}
|
||||
else {
|
||||
mode = "askReadout";
|
||||
}
|
||||
break;
|
||||
case "blockOnlyBlackList":
|
||||
if (blackList.match(url)){
|
||||
mode = "block";
|
||||
@ -161,6 +172,7 @@
|
||||
}
|
||||
});
|
||||
worker.port.emit("setTranslation", "askForPermission", _("askForPermission"));
|
||||
worker.port.emit("setTranslation", "askForReadoutPermission", _("askForReadoutPermission"));
|
||||
checkWorker(worker);
|
||||
},
|
||||
});
|
||||
|
@ -11,6 +11,7 @@ blockMode_options.block everything= alles blockieren
|
||||
blockMode_options.allow only white list= nur Einträge der Whitelist erlauben
|
||||
blockMode_options.ask for permission= um Erlaubnis fragen
|
||||
blockMode_options.block readout API= Auslese-API blockieren
|
||||
blockMode_options.ask for readout API permission= bei Auslese-API um Erlaubnis fragen
|
||||
blockMode_options.block only black list= nur Einträge der Blacklist blockieren
|
||||
blockMode_options.allow everything= alles erlauben
|
||||
|
||||
@ -21,3 +22,4 @@ 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?
|
@ -11,6 +11,7 @@ blockMode_options.block everything= block everything
|
||||
blockMode_options.allow only white list= allow only white list
|
||||
blockMode_options.ask for permission= ask for permission
|
||||
blockMode_options.block readout API= block readout API
|
||||
blockMode_options.ask for readout API permission= ask for readout API permission
|
||||
blockMode_options.block only black list= block only black list
|
||||
blockMode_options.allow everything= allow everything
|
||||
|
||||
@ -21,3 +22,4 @@ 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?
|
@ -20,7 +20,7 @@
|
||||
"name": "blockMode",
|
||||
"title": "block mode",
|
||||
"type": "menulist",
|
||||
"value": "blockReadout",
|
||||
"value": "askReadout",
|
||||
"options": [
|
||||
{
|
||||
"value": "blockEverything",
|
||||
@ -38,6 +38,10 @@
|
||||
"value": "blockReadout",
|
||||
"label": "block readout API"
|
||||
},
|
||||
{
|
||||
"value": "askReadout",
|
||||
"label": "ask for readout API permission"
|
||||
},
|
||||
{
|
||||
"value": "blockOnlyBlackList",
|
||||
"label": "block only black list"
|
||||
|
Loading…
x
Reference in New Issue
Block a user