From 945c2716c9b195baa6a9c3f32f4c3c7e23250364 Mon Sep 17 00:00:00 2001 From: kkapsner Date: Wed, 13 Jan 2021 20:06:03 +0100 Subject: [PATCH] Improved input faking performance further fixes #517 --- lib/modifiedCanvasAPI.js | 17 +++++++++-------- versions/updates.json | 4 ++++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/modifiedCanvasAPI.js b/lib/modifiedCanvasAPI.js index 6de1b79..4935345 100644 --- a/lib/modifiedCanvasAPI.js +++ b/lib/modifiedCanvasAPI.js @@ -227,24 +227,25 @@ notify("fakedInput"); let oldImageData; let x, y, width, height; + const getImageData = window.CanvasRenderingContext2D.prototype.getImageData; const border = 4; try { // "this" is not trustable - it may be not a context 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); + const left = Math.max(0, measurement.actualBoundingBoxLeft); + const top = Math.max(0, measurement.actualBoundingBoxAscent); + width = Math.ceil(measurement.actualBoundingBoxRight + left) + 2 * border; + height = Math.ceil(measurement.actualBoundingBoxDescent + top) + 2 * border; + x = args[1] - border - left; + y = args[2] - border - top; + oldImageData = getImageData.call(this, x, y, width, height); } catch (error){ // nothing to do here } // if "this" is not a correct context the next line will throw an error const ret = original.call(this, ...args); - const newImageData = window.CanvasRenderingContext2D.prototype.getImageData.call(this, x, y, width, height); + const newImageData = getImageData.call(this, x, y, width, height); this.putImageData(randomMixImageData(window, oldImageData, newImageData), x, y); return ret; } diff --git a/versions/updates.json b/versions/updates.json index bf6a254..f3b1db0 100644 --- a/versions/updates.json +++ b/versions/updates.json @@ -161,6 +161,10 @@ { "version": "1.5Alpha20210104", "update_link": "https://canvasblocker.kkapsner.de/versions/canvasblocker_beta-1.5Alpha20210104-an+fx.xpi" + }, + { + "version": "1.5Alpha20210112", + "update_link": "https://canvasblocker.kkapsner.de/versions/canvasblocker_beta-1.5Alpha20210112-an+fx.xpi" } ] }