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(){
|
(function(){
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
@ -12,7 +12,12 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
readAPI: {
|
readAPI: {
|
||||||
status: "allow"
|
status: "allow",
|
||||||
|
askStatus: {
|
||||||
|
askOnce: false,
|
||||||
|
alreadyAsked: false,
|
||||||
|
answer: null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -62,108 +67,86 @@
|
|||||||
return bytes;
|
return bytes;
|
||||||
}());
|
}());
|
||||||
|
|
||||||
var originalToDataURL = unsafeWindow.HTMLCanvasElement.prototype.toDataURL;
|
// Readout API blocking
|
||||||
Object.defineProperty(
|
var fakeFunctions = {
|
||||||
unsafeWindow.HTMLCanvasElement.prototype,
|
toDataURL: {
|
||||||
"toDataURL",
|
object: unsafeWindow.HTMLCanvasElement,
|
||||||
{
|
func: function(){
|
||||||
enumerable: true,
|
var type = arguments[0] || "image/png";
|
||||||
configureable: false,
|
return "data:" + type + ";base64," + btoa(randomImage);
|
||||||
get: exportFunction(function(){
|
}
|
||||||
switch (blockMode.readAPI.status){
|
},
|
||||||
case "allow":
|
toBlob: {
|
||||||
return originalToDataURL;
|
object: unsafeWindow.HTMLCanvasElement,
|
||||||
case "block":
|
func: function(callback){
|
||||||
default:
|
var type = arguments[0] || "image/png";
|
||||||
return exportFunction(
|
var blob = new window.Blob(randomImage, {type: type});
|
||||||
function(){
|
callback(blob);
|
||||||
var type = arguments[0] || "image/png";
|
},
|
||||||
return "data:" + type + ";base64," + btoa(randomImage);
|
exportOptions: {allowCallbacks: true}
|
||||||
},
|
},
|
||||||
unsafeWindow
|
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.keys(fakeFunctions).forEach(function(name){
|
||||||
Object.defineProperty(
|
var fakeFunction = fakeFunctions[name];
|
||||||
unsafeWindow.HTMLCanvasElement.prototype,
|
var original = fakeFunction.object.prototype[name];
|
||||||
"toBlob",
|
Object.defineProperty(
|
||||||
{
|
fakeFunction.object.prototype,
|
||||||
enumerable: true,
|
name,
|
||||||
configureable: false,
|
{
|
||||||
get: exportFunction(function(){
|
enumerable: true,
|
||||||
switch (blockMode.readAPI.status){
|
configureable: false,
|
||||||
case "allow":
|
get: exportFunction(function(){
|
||||||
return originalToBlob;
|
var status = blockMode.readAPI.status;
|
||||||
case "block":
|
if (status === "ask"){
|
||||||
default:
|
var askStatus = blockMode.readAPI.askStatus;
|
||||||
return exportFunction(
|
var allow;
|
||||||
function(callback){
|
if (askStatus.askOnce && askStatus.alreadyAsked){
|
||||||
var type = arguments[0] || "image/png";
|
// console.log("already asked");
|
||||||
var blob = new window.Blob(randomImage, {type: type});
|
allow = askStatus.answer;
|
||||||
callback(blob);
|
}
|
||||||
},
|
else {
|
||||||
unsafeWindow,
|
// console.log("asking");
|
||||||
{allowCallbacks: true}
|
allow = window.confirm(_("askForReadoutPermission"));
|
||||||
);
|
askStatus.alreadyAsked = true;
|
||||||
}
|
askStatus.answer = allow;
|
||||||
}, unsafeWindow)
|
}
|
||||||
}
|
status = allow? "allow": "block";
|
||||||
);
|
}
|
||||||
|
switch (status){
|
||||||
|
case "allow":
|
||||||
|
return original;
|
||||||
|
case "block":
|
||||||
|
default:
|
||||||
|
return exportFunction(
|
||||||
|
fakeFunction.func,
|
||||||
|
unsafeWindow,
|
||||||
|
fakeFunction.exportOptions
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}, unsafeWindow)
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
var originalMozGetAsFile = unsafeWindow.HTMLCanvasElement.prototype.mozGetAsFile;
|
// Translation
|
||||||
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)
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
var _ = function(name){
|
var _ = function(name){
|
||||||
return _[name] || name;
|
return _[name] || name;
|
||||||
};
|
};
|
||||||
@ -171,6 +154,8 @@
|
|||||||
_[name] = translation;
|
_[name] = translation;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Communication with main.js
|
||||||
|
|
||||||
function checkPDF(blocking){
|
function checkPDF(blocking){
|
||||||
if (document.contentType.match(/\/pdf$/i)){
|
if (document.contentType.match(/\/pdf$/i)){
|
||||||
self.port.emit("isPDF", blocking);
|
self.port.emit("isPDF", blocking);
|
||||||
@ -198,6 +183,13 @@
|
|||||||
blockMode.readAPI.status = "block";
|
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(){
|
self.port.on("unblock", function(){
|
||||||
blockMode.getContext.status = "allow";
|
blockMode.getContext.status = "allow";
|
||||||
blockMode.readAPI.status = "allow";
|
blockMode.readAPI.status = "allow";
|
||||||
|
12
lib/main.js
12
lib/main.js
@ -109,6 +109,17 @@
|
|||||||
mode = "blockReadout";
|
mode = "blockReadout";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "askReadout":
|
||||||
|
if (whiteList.match(url)){
|
||||||
|
mode = "unblock";
|
||||||
|
}
|
||||||
|
else if (blackList.match(url)){
|
||||||
|
mode = "block";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
mode = "askReadout";
|
||||||
|
}
|
||||||
|
break;
|
||||||
case "blockOnlyBlackList":
|
case "blockOnlyBlackList":
|
||||||
if (blackList.match(url)){
|
if (blackList.match(url)){
|
||||||
mode = "block";
|
mode = "block";
|
||||||
@ -161,6 +172,7 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
worker.port.emit("setTranslation", "askForPermission", _("askForPermission"));
|
worker.port.emit("setTranslation", "askForPermission", _("askForPermission"));
|
||||||
|
worker.port.emit("setTranslation", "askForReadoutPermission", _("askForReadoutPermission"));
|
||||||
checkWorker(worker);
|
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.allow only white list= nur Einträge der Whitelist erlauben
|
||||||
blockMode_options.ask for permission= um Erlaubnis fragen
|
blockMode_options.ask for permission= um Erlaubnis fragen
|
||||||
blockMode_options.block readout API= Auslese-API blockieren
|
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.block only black list= nur Einträge der Blacklist blockieren
|
||||||
blockMode_options.allow everything= alles erlauben
|
blockMode_options.allow everything= alles erlauben
|
||||||
|
|
||||||
@ -20,4 +21,5 @@ askOnlyOnce_description= Wenn eine Seite öfters versucht, die <canvas>-API abzu
|
|||||||
allowPDFCanvas_title= <canvas> in PDFs erlauben
|
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?
|
||||||
|
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.allow only white list= allow only white list
|
||||||
blockMode_options.ask for permission= ask for permission
|
blockMode_options.ask for permission= ask for permission
|
||||||
blockMode_options.block readout API= block readout API
|
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.block only black list= block only black list
|
||||||
blockMode_options.allow everything= allow everything
|
blockMode_options.allow everything= allow everything
|
||||||
|
|
||||||
@ -20,4 +21,5 @@ askOnlyOnce_description= If a page tries to access the <canvas>-API several time
|
|||||||
allowPDFCanvas_title= Allow canvas in PDFs
|
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>?
|
||||||
|
askForReadoutPermission= Do you want to allow <canvas> readout?
|
@ -20,7 +20,7 @@
|
|||||||
"name": "blockMode",
|
"name": "blockMode",
|
||||||
"title": "block mode",
|
"title": "block mode",
|
||||||
"type": "menulist",
|
"type": "menulist",
|
||||||
"value": "blockReadout",
|
"value": "askReadout",
|
||||||
"options": [
|
"options": [
|
||||||
{
|
{
|
||||||
"value": "blockEverything",
|
"value": "blockEverything",
|
||||||
@ -38,6 +38,10 @@
|
|||||||
"value": "blockReadout",
|
"value": "blockReadout",
|
||||||
"label": "block readout API"
|
"label": "block readout API"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"value": "askReadout",
|
||||||
|
"label": "ask for readout API permission"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"value": "blockOnlyBlackList",
|
"value": "blockOnlyBlackList",
|
||||||
"label": "block only black list"
|
"label": "block only black list"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user