1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-12-22 12:50:36 +01:00

Created fake functions.

This commit is contained in:
kkapsner 2014-10-11 01:17:49 +02:00
parent e8c896e15a
commit 23b5d7672c
2 changed files with 76 additions and 3 deletions

View File

@ -53,6 +53,15 @@
}
);
var randomImage = (function(){
var length = Math.floor(20 + Math.random() * 100);
var bytes = "";
for (var i = 0; i < length; i += 1){
bytes += String.fromCharCode(Math.floor(Math.random() * 256));
}
return bytes;
}());
var originalToDataURL = unsafeWindow.HTMLCanvasElement.prototype.toDataURL;
Object.defineProperty(
unsafeWindow.HTMLCanvasElement.prototype,
@ -66,7 +75,59 @@
return originalToDataURL;
case "block":
default:
return undef;
return exportFunction(
function(){
var type = arguments[0] || "image/png";
return "data:" + type + ";base64," + btoa(randomImage);
},
unsafeWindow
);
}
}, unsafeWindow)
}
);
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)
}
@ -85,7 +146,19 @@
return originalGetImageData;
case "block":
default:
return undef;
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)
}

View File

@ -20,7 +20,7 @@
"name": "blockMode",
"title": "block mode",
"type": "menulist",
"value": "ask",
"value": "blockReadout",
"options": [
{
"value": "blockEverything",