mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2024-12-22 12:50:36 +01:00
parent
b7ba5c2050
commit
a181780020
@ -89,24 +89,20 @@
|
||||
return window.screen;
|
||||
}
|
||||
|
||||
function fakeWidth(args, check){
|
||||
const {prefs, notify, window, original} = check;
|
||||
const originalValue = original.apply(this, window.Array.from(args));
|
||||
const returnValue = Math.round(getScreenDimensions(prefs, window).width);
|
||||
if (originalValue !== returnValue){
|
||||
notify("fakedScreenReadout");
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
function fakeHeight(args, check){
|
||||
const {prefs, notify, window, original} = check;
|
||||
const originalValue = original.apply(this, window.Array.from(args));
|
||||
const returnValue = Math.round(getScreenDimensions(prefs, window).height);
|
||||
if (originalValue !== returnValue){
|
||||
notify("fakedScreenReadout");
|
||||
}
|
||||
return returnValue;
|
||||
function getFaker(dimension){
|
||||
return function fake(args, check){
|
||||
const {prefs, notify, window, original} = check;
|
||||
const originalValue = original.apply(this, window.Array.from(args));
|
||||
const returnValue = (typeof dimension) === "function"?
|
||||
dimension(window):
|
||||
dimension?
|
||||
Math.round(getScreenDimensions(prefs, window)[dimension]):
|
||||
0;
|
||||
if (originalValue !== returnValue){
|
||||
notify("fakedScreenReadout");
|
||||
}
|
||||
return returnValue;
|
||||
};
|
||||
}
|
||||
|
||||
scope.changedGetters = [
|
||||
@ -116,7 +112,7 @@
|
||||
getterGenerator: function(checker){
|
||||
const temp = {
|
||||
get width(){
|
||||
return checkerWrapper(checker, this, arguments, fakeWidth);
|
||||
return checkerWrapper(checker, this, arguments, getFaker("width"));
|
||||
}
|
||||
};
|
||||
return Object.getOwnPropertyDescriptor(temp, "width").get;
|
||||
@ -128,7 +124,7 @@
|
||||
getterGenerator: function(checker){
|
||||
const temp = {
|
||||
get height(){
|
||||
return checkerWrapper(checker, this, arguments, fakeHeight);
|
||||
return checkerWrapper(checker, this, arguments, getFaker("height"));
|
||||
}
|
||||
};
|
||||
return Object.getOwnPropertyDescriptor(temp, "height").get;
|
||||
@ -140,7 +136,7 @@
|
||||
getterGenerator: function(checker){
|
||||
const temp = {
|
||||
get availWidth(){
|
||||
return checkerWrapper(checker, this, arguments, fakeWidth);
|
||||
return checkerWrapper(checker, this, arguments, getFaker("width"));
|
||||
}
|
||||
};
|
||||
return Object.getOwnPropertyDescriptor(temp, "availWidth").get;
|
||||
@ -152,7 +148,7 @@
|
||||
getterGenerator: function(checker){
|
||||
const temp = {
|
||||
get availHeight(){
|
||||
return checkerWrapper(checker, this, arguments, fakeHeight);
|
||||
return checkerWrapper(checker, this, arguments, getFaker("height"));
|
||||
}
|
||||
};
|
||||
return Object.getOwnPropertyDescriptor(temp, "availHeight").get;
|
||||
@ -164,14 +160,7 @@
|
||||
getterGenerator: function(checker){
|
||||
const temp = {
|
||||
get availLeft(){
|
||||
return checkerWrapper(checker, this, arguments, function(args, check){
|
||||
const {notify, window, original} = check;
|
||||
const originalValue = original.apply(this, window.Array.from(args));
|
||||
if (originalValue !== 0){
|
||||
notify("fakedScreenReadout");
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
return checkerWrapper(checker, this, arguments, getFaker(0));
|
||||
}
|
||||
};
|
||||
return Object.getOwnPropertyDescriptor(temp, "availLeft").get;
|
||||
@ -183,14 +172,7 @@
|
||||
getterGenerator: function(checker){
|
||||
const temp = {
|
||||
get availTop(){
|
||||
return checkerWrapper(checker, this, arguments, function(args, check){
|
||||
const {notify, window, original} = check;
|
||||
const originalValue = original.apply(this, window.Array.from(args));
|
||||
if (originalValue !== 0){
|
||||
notify("fakedScreenReadout");
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
return checkerWrapper(checker, this, arguments, getFaker(0));
|
||||
}
|
||||
};
|
||||
return Object.getOwnPropertyDescriptor(temp, "availTop").get;
|
||||
@ -202,15 +184,7 @@
|
||||
getterGenerator: function(checker){
|
||||
const temp = {
|
||||
get outerWidth(){
|
||||
return checkerWrapper(checker, this, arguments, function(args, check){
|
||||
const {notify, window, original} = check;
|
||||
const originalValue = original.apply(this, window.Array.from(args));
|
||||
const returnValue = window.innerWidth;
|
||||
if (originalValue !== returnValue){
|
||||
notify("fakedScreenReadout");
|
||||
}
|
||||
return returnValue;
|
||||
});
|
||||
return checkerWrapper(checker, this, arguments, getFaker(window => window.innerWidth));
|
||||
}
|
||||
};
|
||||
return Object.getOwnPropertyDescriptor(temp, "outerWidth").get;
|
||||
@ -222,15 +196,7 @@
|
||||
getterGenerator: function(checker){
|
||||
const temp = {
|
||||
get outerHeight(){
|
||||
return checkerWrapper(checker, this, arguments, function(args, check){
|
||||
const {notify, window, original} = check;
|
||||
const originalValue = original.apply(this, window.Array.from(args));
|
||||
const returnValue = window.innerHeight;
|
||||
if (originalValue !== returnValue){
|
||||
notify("fakedScreenReadout");
|
||||
}
|
||||
return returnValue;
|
||||
});
|
||||
return checkerWrapper(checker, this, arguments, getFaker(window => window.innerHeight));
|
||||
}
|
||||
};
|
||||
return Object.getOwnPropertyDescriptor(temp, "outerHeight").get;
|
||||
|
@ -357,6 +357,7 @@
|
||||
{
|
||||
name: "fakeMinimalScreenSize",
|
||||
defaultValue: true,
|
||||
mobileDefaultValue: false,
|
||||
urlSpecific: true
|
||||
},
|
||||
{
|
||||
|
@ -126,33 +126,34 @@ addConsistencyTest("media queries: window.matchMedia - big value", function(){
|
||||
);
|
||||
});
|
||||
|
||||
function addResolutionTest(title, callback){
|
||||
var addResolutionTest = function(){
|
||||
"use strict";
|
||||
|
||||
addTest(document.getElementById("resolution"), title, function(resultsNode){
|
||||
["width", "height"].forEach(function(type){
|
||||
var line = document.createElement("div");
|
||||
line.textContent = type + ": ";
|
||||
resultsNode.appendChild(line);
|
||||
|
||||
var number = document.createElement("span");
|
||||
number.className = "result " + type;
|
||||
line.appendChild(number);
|
||||
function compute(){
|
||||
number.textContent = "computing";
|
||||
callback(type).then(function(value){
|
||||
number.textContent = value;
|
||||
return;
|
||||
}).catch(function(error){
|
||||
number.classList.add("failed");
|
||||
number.textContent = error;
|
||||
});
|
||||
}
|
||||
compute();
|
||||
window.addEventListener("resize", compute);
|
||||
return function addResolutionTest(title, callback, properties = ["width", "height"]){
|
||||
addTest(document.getElementById("resolution"), title, function(resultsNode){
|
||||
properties.forEach(function(type){
|
||||
var line = document.createElement("div");
|
||||
line.textContent = type + ": ";
|
||||
resultsNode.appendChild(line);
|
||||
|
||||
var number = document.createElement("span");
|
||||
number.className = "result " + type;
|
||||
line.appendChild(number);
|
||||
function compute(){
|
||||
number.textContent = "computing";
|
||||
callback(type).then(function(value){
|
||||
number.textContent = value;
|
||||
return;
|
||||
}).catch(function(error){
|
||||
number.classList.add("failed");
|
||||
number.textContent = error;
|
||||
});
|
||||
}
|
||||
compute();
|
||||
window.addEventListener("resize", compute);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
}();
|
||||
|
||||
addResolutionTest("screen properties", function(type){
|
||||
"use strict";
|
||||
@ -166,7 +167,7 @@ addResolutionTest("screen properties: avail...", function(type){
|
||||
return Promise.resolve(screen[
|
||||
"avail" + type.substring(0, 1).toUpperCase() + type.substring(1)
|
||||
]);
|
||||
});
|
||||
}, ["width", "height", "left", "top"]);
|
||||
|
||||
addResolutionTest("window properties: inner...", function(type){
|
||||
"use strict";
|
||||
|
Loading…
x
Reference in New Issue
Block a user