mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-07-04 20:46:39 +02:00
parent
692b4616e2
commit
ec128796e3
18 changed files with 328 additions and 3 deletions
|
@ -39,6 +39,7 @@
|
|||
appendModified(require("./modifiedHistoryAPI"));
|
||||
appendModified(require("./modifiedWindowAPI"));
|
||||
appendModified(require("./modifiedDOMRectAPI"));
|
||||
appendModified(require("./modifiedTextMetricsAPI"));
|
||||
appendModified(require("./modifiedNavigatorAPI"));
|
||||
appendModified(require("./modifiedScreenAPI"));
|
||||
}());
|
|
@ -50,7 +50,15 @@
|
|||
}
|
||||
|
||||
const cache = {};
|
||||
const valueCache = [{}, {}, {}, {}];
|
||||
const valueCache = [{}, {}, {}, {}, {}];
|
||||
scope.cache = {
|
||||
valueCache,
|
||||
X: 0,
|
||||
Y: 1,
|
||||
WIDTH: 2,
|
||||
HEIGHT: 3,
|
||||
OTHER: 4
|
||||
};
|
||||
function getFakeDomRect(window, domRect, prefs, notify){
|
||||
const hash = getHash(domRect);
|
||||
let cached = cache[hash];
|
||||
|
|
96
lib/modifiedTextMetricsAPI.js
Normal file
96
lib/modifiedTextMetricsAPI.js
Normal file
|
@ -0,0 +1,96 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
(function(){
|
||||
"use strict";
|
||||
|
||||
let scope;
|
||||
if ((typeof exports) !== "undefined"){
|
||||
scope = exports;
|
||||
}
|
||||
else {
|
||||
scope = require.register("./modifiedTextMetricsAPI", {});
|
||||
}
|
||||
|
||||
const {checkerWrapper, setProperties, getStatusByFlag} = require("./modifiedAPIFunctions");
|
||||
const {byteArrayToString: hash} = require("./hash");
|
||||
const {cache} = require("./modifiedDOMRectAPI");
|
||||
const valueCache = cache.valueCache;
|
||||
|
||||
function getValueHash(value){
|
||||
return hash(new Float32Array([value]));
|
||||
}
|
||||
|
||||
let randomSupply = null;
|
||||
scope.setRandomSupply = function(supply){
|
||||
randomSupply = supply;
|
||||
};
|
||||
|
||||
function getFakeValue(window, value, i, prefs){
|
||||
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 rng = randomSupply.getRng(5, window);
|
||||
const fakedValue = value + 0.01 * (rng(i) / 0xffffffff - 0.5);
|
||||
const fakedHash = getValueHash(fakedValue);
|
||||
cache[valueHash] = fakedValue;
|
||||
cache[fakedHash] = fakedValue;
|
||||
return fakedValue;
|
||||
}
|
||||
}
|
||||
|
||||
function generateChangedTextMetricsPropertyGetter(property, cacheIndex){
|
||||
const changedGetter = {
|
||||
objectGetters: [
|
||||
function(window){return window.TextMetrics && window.TextMetrics.prototype;}
|
||||
],
|
||||
name: property,
|
||||
getterGenerator: function(checker){
|
||||
const temp = {
|
||||
get [property](){
|
||||
return checkerWrapper(checker, this, arguments, function(args, check){
|
||||
const {prefs, notify, window, original} = check;
|
||||
const originalValue = original.call(this, ...args);
|
||||
const returnValue = getFakeValue(window, originalValue, cacheIndex, prefs);
|
||||
if (originalValue !== returnValue){
|
||||
notify("fakedTextMetricsReadout");
|
||||
}
|
||||
return returnValue;
|
||||
});
|
||||
}
|
||||
};
|
||||
return Object.getOwnPropertyDescriptor(temp, property).get;
|
||||
}
|
||||
};
|
||||
return changedGetter;
|
||||
}
|
||||
|
||||
scope.changedGetters = [
|
||||
generateChangedTextMetricsPropertyGetter("width", cache.WIDTH),
|
||||
generateChangedTextMetricsPropertyGetter("actualBoundingBoxAscent", cache.OTHER),
|
||||
generateChangedTextMetricsPropertyGetter("actualBoundingBoxDescent", cache.OTHER),
|
||||
generateChangedTextMetricsPropertyGetter("actualBoundingBoxLeft", cache.OTHER),
|
||||
generateChangedTextMetricsPropertyGetter("actualBoundingBoxRight", cache.OTHER),
|
||||
generateChangedTextMetricsPropertyGetter("alphabeticBaseline", cache.OTHER),
|
||||
generateChangedTextMetricsPropertyGetter("emHeightAscent", cache.OTHER),
|
||||
generateChangedTextMetricsPropertyGetter("emHeightDescent", cache.OTHER),
|
||||
generateChangedTextMetricsPropertyGetter("fontBoundingBoxAscent", cache.OTHER),
|
||||
generateChangedTextMetricsPropertyGetter("fontBoundingBoxDescent", cache.OTHER),
|
||||
generateChangedTextMetricsPropertyGetter("hangingBaseline", cache.OTHER),
|
||||
generateChangedTextMetricsPropertyGetter("ideographicBaseline", cache.OTHER),
|
||||
];
|
||||
|
||||
setProperties({}, scope.changedGetters, {
|
||||
type: "readout",
|
||||
getStatus: getStatusByFlag("protectTextMetrics"),
|
||||
api: "textMetrics"
|
||||
});
|
||||
}());
|
|
@ -117,7 +117,20 @@
|
|||
"getExtentOfChar @ domRect",
|
||||
"intersectionRect @ domRect",
|
||||
"boundingClientRect @ domRect",
|
||||
"rootBounds",
|
||||
"rootBounds @ domRect",
|
||||
{name: "TextMetrics-API", level: 1},
|
||||
"width @ textMetrics",
|
||||
"actualBoundingBoxAscent @ textMetrics",
|
||||
"actualBoundingBoxDescent @ textMetrics",
|
||||
"actualBoundingBoxLeft @ textMetrics",
|
||||
"actualBoundingBoxRight @ textMetrics",
|
||||
"alphabeticBaseline @ textMetrics",
|
||||
"emHeightAscent @ textMetrics",
|
||||
"emHeightDescent @ textMetrics",
|
||||
"fontBoundingBoxAscent @ textMetrics",
|
||||
"fontBoundingBoxDescent @ textMetrics",
|
||||
"hangingBaseline @ textMetrics",
|
||||
"ideographicBaseline @ textMetrics",
|
||||
{name: "Navigator-API", level: 1},
|
||||
"appCodeName @ navigator",
|
||||
"appName @ navigator",
|
||||
|
@ -335,6 +348,11 @@
|
|||
name: "domRectIntegerFactor",
|
||||
defaultValue: 4
|
||||
},
|
||||
{
|
||||
name: "protectTextMetrics",
|
||||
defaultValue: true,
|
||||
urlSpecific: true
|
||||
},
|
||||
{
|
||||
name: "blockDataURLs",
|
||||
defaultValue: true,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue