mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-01-20 18:38:32 +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,11 +26,12 @@
|
|||||||
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){
|
||||||
|
(Array.isArray(changedFunction.object)? changedFunction.object: [changedFunction.object]).forEach(function(object){
|
||||||
|
var original = window.wrappedJSObject[object].prototype[name];
|
||||||
|
|
||||||
Object.defineProperty(
|
Object.defineProperty(
|
||||||
window.wrappedJSObject[changedFunction.object].prototype,
|
window.wrappedJSObject[object].prototype,
|
||||||
name,
|
name,
|
||||||
{
|
{
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
@ -76,6 +77,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -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