mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-01-03 10:31:54 +01:00
Removed bug with faking webgl and added readPixels for webgl2.
Fixes #96 and #97.
This commit is contained in:
parent
6748771402
commit
6d7a9fc22a
@ -26,56 +26,58 @@
|
|||||||
if (siteStatus.mode !== "allow"){
|
if (siteStatus.mode !== "allow"){
|
||||||
apiNames.forEach(function(name){
|
apiNames.forEach(function(name){
|
||||||
var changedFunction = changedFunctions[name];
|
var changedFunction = changedFunctions[name];
|
||||||
var original = window.wrappedJSObject[changedFunction.object].prototype[name];
|
|
||||||
|
|
||||||
if (changedFunction.getStatus(undefined, siteStatus).active){
|
if (changedFunction.getStatus(undefined, siteStatus).active){
|
||||||
Object.defineProperty(
|
(Array.isArray(changedFunction.object)? changedFunction.object: [changedFunction.object]).forEach(function(object){
|
||||||
window.wrappedJSObject[changedFunction.object].prototype,
|
var original = window.wrappedJSObject[object].prototype[name];
|
||||||
name,
|
|
||||||
{
|
Object.defineProperty(
|
||||||
enumerable: true,
|
window.wrappedJSObject[object].prototype,
|
||||||
configureable: false,
|
name,
|
||||||
get: function(){
|
{
|
||||||
if (!window.location.href){
|
enumerable: true,
|
||||||
return undef;
|
configureable: false,
|
||||||
}
|
get: function(){
|
||||||
var error = new Error();
|
if (!window.location.href){
|
||||||
if (checkStack(error.stack)){
|
return undef;
|
||||||
return original;
|
|
||||||
}
|
|
||||||
var funcStatus = changedFunction.getStatus(this, siteStatus);
|
|
||||||
|
|
||||||
if (funcStatus.active){
|
|
||||||
if (funcStatus.mode === "ask"){
|
|
||||||
funcStatus.mode = ask({window: window, type: changedFunction.type, canvas: this, errorStack: error.stack});
|
|
||||||
}
|
}
|
||||||
switch (funcStatus.mode){
|
var error = new Error();
|
||||||
case "allow":
|
if (checkStack(error.stack)){
|
||||||
return original;
|
return original;
|
||||||
case "fake":
|
}
|
||||||
setRandomSupplyByType(prefs("rng"));
|
var funcStatus = changedFunction.getStatus(this, siteStatus);
|
||||||
var fake = changedFunction.fakeGenerator(prefs, function(messageId){
|
|
||||||
notify({url: window.location.href, errorStack: error.stack, messageId});
|
if (funcStatus.active){
|
||||||
}, original);
|
if (funcStatus.mode === "ask"){
|
||||||
switch (fake){
|
funcStatus.mode = ask({window: window, type: changedFunction.type, canvas: this, errorStack: error.stack});
|
||||||
case true:
|
}
|
||||||
return original;
|
switch (funcStatus.mode){
|
||||||
case false:
|
case "allow":
|
||||||
return undef;
|
return original;
|
||||||
default:
|
case "fake":
|
||||||
return exportFunction(fake, window.wrappedJSObject);
|
setRandomSupplyByType(prefs("rng"));
|
||||||
}
|
var fake = changedFunction.fakeGenerator(prefs, function(messageId){
|
||||||
//case "block":
|
notify({url: window.location.href, errorStack: error.stack, messageId});
|
||||||
default:
|
}, original);
|
||||||
return undef;
|
switch (fake){
|
||||||
|
case true:
|
||||||
|
return original;
|
||||||
|
case false:
|
||||||
|
return undef;
|
||||||
|
default:
|
||||||
|
return exportFunction(fake, window.wrappedJSObject);
|
||||||
|
}
|
||||||
|
//case "block":
|
||||||
|
default:
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return original;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else {
|
|
||||||
return original;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
);
|
||||||
);
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -17,30 +17,37 @@
|
|||||||
window.HTMLCanvasElement.prototype.getContext.call(canvas, "experimental-webgl2");
|
window.HTMLCanvasElement.prototype.getContext.call(canvas, "experimental-webgl2");
|
||||||
}
|
}
|
||||||
function getImageData(window, context){
|
function getImageData(window, context){
|
||||||
|
var imageData;
|
||||||
|
var source;
|
||||||
if (context instanceof window.CanvasRenderingContext2D){
|
if (context instanceof window.CanvasRenderingContext2D){
|
||||||
return window.CanvasRenderingContext2D.prototype.getImageData.call(context, 0, 0, context.canvas.width, context.canvas.height);
|
imageData = window.CanvasRenderingContext2D.prototype.getImageData.call(context, 0, 0, context.canvas.width, context.canvas.height);
|
||||||
|
source = imageData.data;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var imageData = new window.wrappedJSObject.ImageData(context.canvas.width, context.canvas.height);
|
var imageData = new window.wrappedJSObject.ImageData(context.canvas.width, context.canvas.height);
|
||||||
|
var source = new Uint8Array(imageData.data.length);
|
||||||
window.WebGLRenderingContext.prototype.readPixels.call(
|
window.WebGLRenderingContext.prototype.readPixels.call(
|
||||||
context,
|
context,
|
||||||
0, 0, context.canvas.width, context.canvas.height,
|
0, 0, context.canvas.width, context.canvas.height,
|
||||||
context.RGBA, context.UNSIGNED_BYTE,
|
context.RGBA, context.UNSIGNED_BYTE,
|
||||||
imageData.data
|
source
|
||||||
);
|
);
|
||||||
return imageData;
|
|
||||||
}
|
}
|
||||||
|
return {
|
||||||
|
imageData,
|
||||||
|
source
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFakeCanvas(window, original){
|
function getFakeCanvas(window, original){
|
||||||
var context = getContext(window, original);
|
var context = getContext(window, original);
|
||||||
var imageData = getImageData(window, context);
|
var {imageData, source} = getImageData(window, context);
|
||||||
var data = imageData.data;
|
var desc = imageData.data;
|
||||||
var l = data.length;
|
var l = desc.length;
|
||||||
var rng = randomSupply.getRng(l, window);
|
var rng = randomSupply.getRng(l, window);
|
||||||
|
|
||||||
for (var i = 0; i < l; i += 1){
|
for (var i = 0; i < l; i += 10){
|
||||||
data[i] = rng(data[i], i);
|
desc[i] = rng(source[i], i);
|
||||||
}
|
}
|
||||||
var canvas = original.cloneNode(true);
|
var canvas = original.cloneNode(true);
|
||||||
context = window.HTMLCanvasElement.prototype.getContext.call(canvas, "2d");
|
context = window.HTMLCanvasElement.prototype.getContext.call(canvas, "2d");
|
||||||
@ -249,7 +256,7 @@
|
|||||||
status.active = hasType(status, "readout") || hasType(status, "input");
|
status.active = hasType(status, "readout") || hasType(status, "input");
|
||||||
return status;
|
return status;
|
||||||
},
|
},
|
||||||
object: "WebGLRenderingContext",
|
object: ["WebGLRenderingContext", "WebGL2RenderingContext"],
|
||||||
fakeGenerator: function(prefs, notify){
|
fakeGenerator: function(prefs, notify){
|
||||||
return function readPixels(x, y, width, height, format, type, pixels){
|
return function readPixels(x, y, width, height, format, type, pixels){
|
||||||
// not able to use the getFakeCanvas function because the context type is wrong...
|
// not able to use the getFakeCanvas function because the context type is wrong...
|
||||||
|
Loading…
x
Reference in New Issue
Block a user