1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-06-08 06:17:47 +02:00

Last adjustments to screen protection

Fixes #220
This commit is contained in:
kkapsner 2019-12-02 19:17:54 +01:00
parent b7ba5c2050
commit a181780020
3 changed files with 50 additions and 82 deletions

View File

@ -89,24 +89,20 @@
return window.screen; return window.screen;
} }
function fakeWidth(args, check){ function getFaker(dimension){
return function fake(args, check){
const {prefs, notify, window, original} = check; const {prefs, notify, window, original} = check;
const originalValue = original.apply(this, window.Array.from(args)); const originalValue = original.apply(this, window.Array.from(args));
const returnValue = Math.round(getScreenDimensions(prefs, window).width); const returnValue = (typeof dimension) === "function"?
if (originalValue !== returnValue){ dimension(window):
notify("fakedScreenReadout"); dimension?
} Math.round(getScreenDimensions(prefs, window)[dimension]):
return returnValue; 0;
}
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){ if (originalValue !== returnValue){
notify("fakedScreenReadout"); notify("fakedScreenReadout");
} }
return returnValue; return returnValue;
};
} }
scope.changedGetters = [ scope.changedGetters = [
@ -116,7 +112,7 @@
getterGenerator: function(checker){ getterGenerator: function(checker){
const temp = { const temp = {
get width(){ get width(){
return checkerWrapper(checker, this, arguments, fakeWidth); return checkerWrapper(checker, this, arguments, getFaker("width"));
} }
}; };
return Object.getOwnPropertyDescriptor(temp, "width").get; return Object.getOwnPropertyDescriptor(temp, "width").get;
@ -128,7 +124,7 @@
getterGenerator: function(checker){ getterGenerator: function(checker){
const temp = { const temp = {
get height(){ get height(){
return checkerWrapper(checker, this, arguments, fakeHeight); return checkerWrapper(checker, this, arguments, getFaker("height"));
} }
}; };
return Object.getOwnPropertyDescriptor(temp, "height").get; return Object.getOwnPropertyDescriptor(temp, "height").get;
@ -140,7 +136,7 @@
getterGenerator: function(checker){ getterGenerator: function(checker){
const temp = { const temp = {
get availWidth(){ get availWidth(){
return checkerWrapper(checker, this, arguments, fakeWidth); return checkerWrapper(checker, this, arguments, getFaker("width"));
} }
}; };
return Object.getOwnPropertyDescriptor(temp, "availWidth").get; return Object.getOwnPropertyDescriptor(temp, "availWidth").get;
@ -152,7 +148,7 @@
getterGenerator: function(checker){ getterGenerator: function(checker){
const temp = { const temp = {
get availHeight(){ get availHeight(){
return checkerWrapper(checker, this, arguments, fakeHeight); return checkerWrapper(checker, this, arguments, getFaker("height"));
} }
}; };
return Object.getOwnPropertyDescriptor(temp, "availHeight").get; return Object.getOwnPropertyDescriptor(temp, "availHeight").get;
@ -164,14 +160,7 @@
getterGenerator: function(checker){ getterGenerator: function(checker){
const temp = { const temp = {
get availLeft(){ get availLeft(){
return checkerWrapper(checker, this, arguments, function(args, check){ return checkerWrapper(checker, this, arguments, getFaker(0));
const {notify, window, original} = check;
const originalValue = original.apply(this, window.Array.from(args));
if (originalValue !== 0){
notify("fakedScreenReadout");
}
return 0;
});
} }
}; };
return Object.getOwnPropertyDescriptor(temp, "availLeft").get; return Object.getOwnPropertyDescriptor(temp, "availLeft").get;
@ -183,14 +172,7 @@
getterGenerator: function(checker){ getterGenerator: function(checker){
const temp = { const temp = {
get availTop(){ get availTop(){
return checkerWrapper(checker, this, arguments, function(args, check){ return checkerWrapper(checker, this, arguments, getFaker(0));
const {notify, window, original} = check;
const originalValue = original.apply(this, window.Array.from(args));
if (originalValue !== 0){
notify("fakedScreenReadout");
}
return 0;
});
} }
}; };
return Object.getOwnPropertyDescriptor(temp, "availTop").get; return Object.getOwnPropertyDescriptor(temp, "availTop").get;
@ -202,15 +184,7 @@
getterGenerator: function(checker){ getterGenerator: function(checker){
const temp = { const temp = {
get outerWidth(){ get outerWidth(){
return checkerWrapper(checker, this, arguments, function(args, check){ return checkerWrapper(checker, this, arguments, getFaker(window => window.innerWidth));
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 Object.getOwnPropertyDescriptor(temp, "outerWidth").get; return Object.getOwnPropertyDescriptor(temp, "outerWidth").get;
@ -222,15 +196,7 @@
getterGenerator: function(checker){ getterGenerator: function(checker){
const temp = { const temp = {
get outerHeight(){ get outerHeight(){
return checkerWrapper(checker, this, arguments, function(args, check){ return checkerWrapper(checker, this, arguments, getFaker(window => window.innerHeight));
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 Object.getOwnPropertyDescriptor(temp, "outerHeight").get; return Object.getOwnPropertyDescriptor(temp, "outerHeight").get;

View File

@ -357,6 +357,7 @@
{ {
name: "fakeMinimalScreenSize", name: "fakeMinimalScreenSize",
defaultValue: true, defaultValue: true,
mobileDefaultValue: false,
urlSpecific: true urlSpecific: true
}, },
{ {

View File

@ -126,11 +126,11 @@ addConsistencyTest("media queries: window.matchMedia - big value", function(){
); );
}); });
function addResolutionTest(title, callback){ var addResolutionTest = function(){
"use strict"; "use strict";
return function addResolutionTest(title, callback, properties = ["width", "height"]){
addTest(document.getElementById("resolution"), title, function(resultsNode){ addTest(document.getElementById("resolution"), title, function(resultsNode){
["width", "height"].forEach(function(type){ properties.forEach(function(type){
var line = document.createElement("div"); var line = document.createElement("div");
line.textContent = type + ": "; line.textContent = type + ": ";
resultsNode.appendChild(line); resultsNode.appendChild(line);
@ -152,7 +152,8 @@ function addResolutionTest(title, callback){
window.addEventListener("resize", compute); window.addEventListener("resize", compute);
}); });
}); });
} };
}();
addResolutionTest("screen properties", function(type){ addResolutionTest("screen properties", function(type){
"use strict"; "use strict";
@ -166,7 +167,7 @@ addResolutionTest("screen properties: avail...", function(type){
return Promise.resolve(screen[ return Promise.resolve(screen[
"avail" + type.substring(0, 1).toUpperCase() + type.substring(1) "avail" + type.substring(0, 1).toUpperCase() + type.substring(1)
]); ]);
}); }, ["width", "height", "left", "top"]);
addResolutionTest("window properties: inner...", function(type){ addResolutionTest("window properties: inner...", function(type){
"use strict"; "use strict";