1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-12-22 12:50:36 +01:00

Added support for pixel fractions

Pixel fractions can be controlled by CSS. These fractions must not be
faked.

For #236.
This commit is contained in:
kkapsner 2018-09-05 15:53:01 +02:00
parent 1d5953e8c7
commit df1d59cf52
5 changed files with 34 additions and 14 deletions

View File

@ -898,6 +898,15 @@
"description": ""
},
"domRectIntegerFactor_title": {
"message": "DOMRect integer factor",
"description": ""
},
"domRectIntegerFactor_description": {
"message": "Some fraction of a pixel can be controlled by CSS. To prevent detection values of a DOMRect that multiplied with this factor are integers will not be altered.",
"description": ""
},
"theme_title": {
"message": "Theme",
"description": ""

View File

@ -337,7 +337,7 @@
descriptor.get = exportFunction(getter, window);
if (descriptor.hasOwnProperty("set") && changedGetter.setterGenerator){
const setter = changedGetter.setterGenerator(window, descriptor.set);
const setter = changedGetter.setterGenerator(window, descriptor.set, prefs);
descriptor.set = exportFunction(setter, window);
}

View File

@ -45,11 +45,11 @@
function getDOMRectRegistration(domRect){
return registeredRects.get(getWrapped(domRect));
}
function getFakeDomRect(window, domRect, notify){
function getFakeDomRect(window, domRect, prefs, notify){
var rng = randomSupply.getRng(4, window);
function getFakeValue(value, i){
if (value % 1 === 0){
if ((value * prefs("domRectIntegerFactor", window.location)) % 1 === 0){
return value;
}
else {
@ -159,17 +159,17 @@
if (prefs("protectDOMRect", window.location)){
const registration = getDOMRectRegistration(this);
if (registration){
return getFakeDomRect(window, this, registration.notify)[property];
return getFakeDomRect(window, this, prefs, registration.notify)[property];
}
}
return originalValue;
};
}
function setProperty(domRect, window, original, newValue, property){ // eslint-disable-line max-params
function setProperty(domRect, window, original, newValue, property, prefs){ // eslint-disable-line max-params
const registration = getDOMRectRegistration(domRect);
if (registration){
const fakeDomRect = getFakeDomRect(window, domRect, registration.notify);
const fakeDomRect = getFakeDomRect(window, domRect, prefs, registration.notify);
registeredRects.delete(getWrapped(domRect));
["x", "y", "width", "height"].forEach(function(prop){
if (prop === property){
@ -200,10 +200,10 @@
};
return Object.getOwnPropertyDescriptor(temp, "x").get;
},
setterGenerator: function(window, original){
setterGenerator: function(window, original, prefs){
const temp = {
set x(x){
setProperty(this, window, original, x, "x");
setProperty(this, window, original, x, "x", prefs);
}
};
return Object.getOwnPropertyDescriptor(temp, "x").set;
@ -223,10 +223,10 @@
};
return Object.getOwnPropertyDescriptor(temp, "y").get;
},
setterGenerator: function(window, original){
setterGenerator: function(window, original, prefs){
const temp = {
set y(y){
setProperty(this, window, original, y, "y");
setProperty(this, window, original, y, "y", prefs);
}
};
return Object.getOwnPropertyDescriptor(temp, "y").set;
@ -246,10 +246,10 @@
};
return Object.getOwnPropertyDescriptor(temp, "width").get;
},
setterGenerator: function(window, original){
setterGenerator: function(window, original, prefs){
const temp = {
set width(width){
setProperty(this, window, original, width, "width");
setProperty(this, window, original, width, "width", prefs);
}
};
return Object.getOwnPropertyDescriptor(temp, "width").set;
@ -269,10 +269,10 @@
};
return Object.getOwnPropertyDescriptor(temp, "height").get;
},
setterGenerator: function(window, original){
setterGenerator: function(window, original, prefs){
const temp = {
set height(height){
setProperty(this, window, original, height, "height");
setProperty(this, window, original, height, "height", prefs);
}
};
return Object.getOwnPropertyDescriptor(temp, "height").set;

View File

@ -267,6 +267,10 @@
defaultValue: true,
urlSpecific: true
},
{
name: "domRectIntegerFactor",
defaultValue: 4
},
{
name: "blockDataURLs",
defaultValue: true

View File

@ -411,6 +411,13 @@
"displayAdvancedSettings": [true]
}
},
{
"name": "domRectIntegerFactor",
"displayDependencies": {
"protectDOMRect": [true],
"displayAdvancedSettings": [true]
}
},
"misc",
{
"name": "theme"