Added value cache for DOMRect

Fixes #272
This commit is contained in:
kkapsner 2018-09-29 09:41:43 +02:00
parent ab344294d7
commit 0f07cde869
2 changed files with 25 additions and 11 deletions

View File

@ -26,6 +26,9 @@
function getHash(domRect){
return hash(new Float64Array([domRect.x, domRect.y, domRect.width, domRect.height]));
}
function getValueHash(value){
return hash(new Float32Array([value]));
}
const registeredRects = new WeakMap();
function registerDOMRect(domRect, notify){
@ -46,21 +49,32 @@
}
const cache = {};
const valueCache = [{}, {}, {}, {}];
function getFakeDomRect(window, domRect, prefs, notify){
var rng = randomSupply.getRng(4, window);
function getFakeValue(value, i){
if ((value * prefs("domRectIntegerFactor", window.location)) % 1 === 0){
return value;
}
else {
return value + 0.01 * (rng(i) / 0xffffffff - 0.5);
}
}
const hash = getHash(domRect);
let cached = cache[hash];
if (!cached){
notify("fakedDOMRectReadout");
const rng = randomSupply.getRng(4, window);
const getFakeValue = function getFakeValue(value, i){
const valueHash = getValueHash(value);
const cache = valueCache[i];
let cachedValue = cache[valueHash];
if (typeof cachedValue === "number"){
return cachedValue;
}
if ((value * prefs("domRectIntegerFactor", window.location)) % 1 === 0){
cache[valueHash] = value;
return value;
}
else {
const fakedValue = value + 0.01 * (rng(i) / 0xffffffff - 0.5);
const fakedHash = getValueHash(fakedValue);
cache[valueHash] = fakedValue;
cache[fakedHash] = fakedValue;
return fakedValue;
}
};
cached = new domRect.constructor(
getFakeValue(domRect.x, 0),
getFakeValue(domRect.y, 1),

View File

@ -6,7 +6,7 @@ Version 0.5.5:
-
fixes:
-
- Google images did not work for some users
known issues:
- if a data URL is blocked the page action button does not appear