mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-01-03 02:21:53 +01:00
parent
fcbc622cef
commit
b4a744660b
@ -226,17 +226,26 @@
|
|||||||
if (!this || canvasSizeShouldBeFaked(this.canvas, prefs)){
|
if (!this || canvasSizeShouldBeFaked(this.canvas, prefs)){
|
||||||
notify("fakedInput");
|
notify("fakedInput");
|
||||||
let oldImageData;
|
let oldImageData;
|
||||||
|
let x, y, width, height;
|
||||||
|
const border = 4;
|
||||||
try {
|
try {
|
||||||
// "this" is not trustable - it may be not a context
|
// "this" is not trustable - it may be not a context
|
||||||
oldImageData = getImageData(window, this).imageData;
|
const measurement = window.CanvasRenderingContext2D.prototype.measureText.call(this, args[0]);
|
||||||
|
width = Math.ceil(measurement.actualBoundingBoxRight + measurement.actualBoundingBoxLeft) + border;
|
||||||
|
height = Math.ceil(measurement.actualBoundingBoxDescent + measurement.actualBoundingBoxAscent) + border;
|
||||||
|
x = Math.max(0, args[1] - width);
|
||||||
|
y = Math.max(0, args[2] - height);
|
||||||
|
width = Math.min(3 * width, this.canvas.width - x);
|
||||||
|
height = Math.min(3 * height, this.canvas.height - y);
|
||||||
|
oldImageData = window.CanvasRenderingContext2D.prototype.getImageData.call(this, x, y, width, height);
|
||||||
}
|
}
|
||||||
catch (error){
|
catch (error){
|
||||||
// nothing to do here
|
// nothing to do here
|
||||||
}
|
}
|
||||||
// if "this" is not a correct context the next line will throw an error
|
// if "this" is not a correct context the next line will throw an error
|
||||||
const ret = original.call(this, ...args);
|
const ret = original.call(this, ...args);
|
||||||
const newImageData = getImageData(window, this).imageData;
|
const newImageData = window.CanvasRenderingContext2D.prototype.getImageData.call(this, x, y, width, height);
|
||||||
this.putImageData(randomMixImageData(window, oldImageData, newImageData), 0, 0);
|
this.putImageData(randomMixImageData(window, oldImageData, newImageData), x, y);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -4,6 +4,7 @@ Version 1.5:
|
|||||||
|
|
||||||
new features:
|
new features:
|
||||||
- added {empty}, {false} and {undefined} to webGL preference parameters (i.e. VENDOR, RENDERER, UNMASKED_VENDOR_WEBGL and UNMASKED_RENDERER_WEBGL)
|
- added {empty}, {false} and {undefined} to webGL preference parameters (i.e. VENDOR, RENDERER, UNMASKED_VENDOR_WEBGL and UNMASKED_RENDERER_WEBGL)
|
||||||
|
- improved performance for protected canvas part "input"
|
||||||
|
|
||||||
fixes:
|
fixes:
|
||||||
- protection of DOM manipulations on unloaded windows may break websites
|
- protection of DOM manipulations on unloaded windows may break websites
|
||||||
|
Loading…
x
Reference in New Issue
Block a user