mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-01-03 10:31:54 +01:00
Remove code duplications and cleanup
This commit is contained in:
parent
8e414becf0
commit
32f9ea7447
@ -50,6 +50,7 @@
|
|||||||
"no-unreachable": "warn",
|
"no-unreachable": "warn",
|
||||||
"no-unused-vars": "off",
|
"no-unused-vars": "off",
|
||||||
"no-use-before-define": ["error", {"functions": false}],
|
"no-use-before-define": ["error", {"functions": false}],
|
||||||
|
"no-useless-rename": "warn",
|
||||||
"no-var": "error",
|
"no-var": "error",
|
||||||
"quotes": ["error", "double"],
|
"quotes": ["error", "double"],
|
||||||
"semi": ["error", "always"],
|
"semi": ["error", "always"],
|
||||||
|
@ -30,6 +30,14 @@
|
|||||||
return undefined;
|
return undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
scope.getStatusByFlag = function getStatusByFlag(flag){
|
||||||
|
return function getStatus(obj, status, prefs){
|
||||||
|
status = Object.create(status);
|
||||||
|
status.active = prefs(flag, status.url);
|
||||||
|
return status;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
scope.setFunctionProperties = function setFunctionProperties(functions, data){
|
scope.setFunctionProperties = function setFunctionProperties(functions, data){
|
||||||
Object.keys(functions).forEach(function(key){
|
Object.keys(functions).forEach(function(key){
|
||||||
const func = functions[key];
|
const func = functions[key];
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
const {sha256String: hashing} = require("./hash");
|
const {sha256String: hashing} = require("./hash");
|
||||||
const {checkerWrapper} = require("./modifiedAPIFunctions");
|
const {checkerWrapper, setFunctionProperties, getStatusByFlag} = require("./modifiedAPIFunctions");
|
||||||
|
|
||||||
let randomSupply = null;
|
let randomSupply = null;
|
||||||
|
|
||||||
@ -156,12 +156,6 @@
|
|||||||
randomSupply = supply;
|
randomSupply = supply;
|
||||||
};
|
};
|
||||||
|
|
||||||
function getStatus(obj, status, prefs){
|
|
||||||
status = Object.create(status);
|
|
||||||
status.active = prefs("protectAudio", status.url);
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
const getChannelDataAlreadyFakedArrays = new WeakMap();
|
const getChannelDataAlreadyFakedArrays = new WeakMap();
|
||||||
// changed functions and their fakes
|
// changed functions and their fakes
|
||||||
scope.changedFunctions = {
|
scope.changedFunctions = {
|
||||||
@ -275,9 +269,10 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
Object.keys(scope.changedFunctions).forEach(function(key){
|
|
||||||
scope.changedFunctions[key].type = "readout";
|
setFunctionProperties(scope.changedFunctions, {
|
||||||
scope.changedFunctions[key].getStatus = getStatus;
|
type: "readout",
|
||||||
scope.changedFunctions[key].api = "audio";
|
getStatus: getStatusByFlag("protectAudio"),
|
||||||
|
api: "audio"
|
||||||
});
|
});
|
||||||
}());
|
}());
|
@ -12,7 +12,7 @@
|
|||||||
scope = require.register("./modifiedDOMRectAPI", {});
|
scope = require.register("./modifiedDOMRectAPI", {});
|
||||||
}
|
}
|
||||||
|
|
||||||
const {getWrapped, checkerWrapper, setProperties: setProperties} = require("./modifiedAPIFunctions");
|
const {getWrapped, checkerWrapper, setProperties, getStatusByFlag} = require("./modifiedAPIFunctions");
|
||||||
const {byteArrayToString: hash} = require("./hash");
|
const {byteArrayToString: hash} = require("./hash");
|
||||||
|
|
||||||
|
|
||||||
@ -87,6 +87,15 @@
|
|||||||
return cached;
|
return cached;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function registerCallback(args, check){
|
||||||
|
const {prefs, notify, window, original} = check;
|
||||||
|
const originalValue = args.length?
|
||||||
|
original.apply(this, window.Array.from(args)):
|
||||||
|
original.call(this);
|
||||||
|
registerDOMRect(originalValue, notify, window, prefs);
|
||||||
|
return originalValue;
|
||||||
|
}
|
||||||
|
|
||||||
scope.changedFunctions = {
|
scope.changedFunctions = {
|
||||||
getClientRects: {
|
getClientRects: {
|
||||||
object: ["Range", "Element"],
|
object: ["Range", "Element"],
|
||||||
@ -107,12 +116,7 @@
|
|||||||
object: ["Range", "Element"],
|
object: ["Range", "Element"],
|
||||||
fakeGenerator: function(checker){
|
fakeGenerator: function(checker){
|
||||||
return function getBoundingClientRect(){
|
return function getBoundingClientRect(){
|
||||||
return checkerWrapper(checker, this, arguments, function(args, check){
|
return checkerWrapper(checker, this, arguments, registerCallback);
|
||||||
const {prefs, notify, window, original} = check;
|
|
||||||
const ret = args.length? original.apply(this, window.Array.from(args)): original.call(this);
|
|
||||||
registerDOMRect(ret, notify, window, prefs);
|
|
||||||
return ret;
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -121,12 +125,7 @@
|
|||||||
object: ["DOMQuad"],
|
object: ["DOMQuad"],
|
||||||
fakeGenerator: function(checker){
|
fakeGenerator: function(checker){
|
||||||
return function getBounds(){
|
return function getBounds(){
|
||||||
return checkerWrapper(checker, this, arguments, function(args, check){
|
return checkerWrapper(checker, this, arguments, registerCallback);
|
||||||
const {prefs, notify, window, original} = check;
|
|
||||||
const ret = args.length? original.apply(this, window.Array.from(args)): original.call(this);
|
|
||||||
registerDOMRect(ret, notify, window, prefs);
|
|
||||||
return ret;
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -134,25 +133,15 @@
|
|||||||
object: ["SVGGraphicsElement"],
|
object: ["SVGGraphicsElement"],
|
||||||
fakeGenerator: function(checker){
|
fakeGenerator: function(checker){
|
||||||
return function getBBox(){
|
return function getBBox(){
|
||||||
return checkerWrapper(checker, this, arguments, function(args, check){
|
return checkerWrapper(checker, this, arguments, registerCallback);
|
||||||
const {prefs, notify, window, original} = check;
|
|
||||||
const ret = args.length? original.apply(this, window.Array.from(args)): original.call(this);
|
|
||||||
registerDOMRect(ret, notify, window, prefs);
|
|
||||||
return ret;
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getExtentOfChar: {
|
getExtentOfChar: {
|
||||||
object: ["SVGTextContentElement"],
|
object: ["SVGTextContentElement"],
|
||||||
fakeGenerator: function(checker){
|
fakeGenerator: function(checker){
|
||||||
return function getBBox(){
|
return function getExtentOfChar(){
|
||||||
return checkerWrapper(checker, this, arguments, function(args, check){
|
return checkerWrapper(checker, this, arguments, registerCallback);
|
||||||
const {prefs, notify, window, original} = check;
|
|
||||||
const ret = args.length? original.apply(this, window.Array.from(args)): original.call(this);
|
|
||||||
registerDOMRect(ret, notify, window, prefs);
|
|
||||||
return ret;
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -234,14 +223,7 @@
|
|||||||
getterGenerator: function(checker){
|
getterGenerator: function(checker){
|
||||||
const temp = {
|
const temp = {
|
||||||
get intersectionRect(){
|
get intersectionRect(){
|
||||||
return checkerWrapper(checker, this, arguments, function(args, check){
|
return checkerWrapper(checker, this, arguments, registerCallback);
|
||||||
const {prefs, notify, window, original} = check;
|
|
||||||
const originalValue = args.length?
|
|
||||||
original.apply(this, window.Array.from(args)):
|
|
||||||
original.call(this);
|
|
||||||
registerDOMRect(originalValue, notify, window, prefs);
|
|
||||||
return originalValue;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return Object.getOwnPropertyDescriptor(temp, "intersectionRect").get;
|
return Object.getOwnPropertyDescriptor(temp, "intersectionRect").get;
|
||||||
@ -257,14 +239,7 @@
|
|||||||
getterGenerator: function(checker){
|
getterGenerator: function(checker){
|
||||||
const temp = {
|
const temp = {
|
||||||
get boundingClientRect(){
|
get boundingClientRect(){
|
||||||
return checkerWrapper(checker, this, arguments, function(args, check){
|
return checkerWrapper(checker, this, arguments, registerCallback);
|
||||||
const {prefs, notify, window, original} = check;
|
|
||||||
const originalValue = args.length?
|
|
||||||
original.apply(this, window.Array.from(args)):
|
|
||||||
original.call(this);
|
|
||||||
registerDOMRect(originalValue, notify, window, prefs);
|
|
||||||
return originalValue;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return Object.getOwnPropertyDescriptor(temp, "boundingClientRect").get;
|
return Object.getOwnPropertyDescriptor(temp, "boundingClientRect").get;
|
||||||
@ -280,14 +255,7 @@
|
|||||||
getterGenerator: function(checker){
|
getterGenerator: function(checker){
|
||||||
const temp = {
|
const temp = {
|
||||||
get rootBounds(){
|
get rootBounds(){
|
||||||
return checkerWrapper(checker, this, arguments, function(args, check){
|
return checkerWrapper(checker, this, arguments, registerCallback);
|
||||||
const {prefs, notify, window, original} = check;
|
|
||||||
const originalValue = args.length?
|
|
||||||
original.apply(this, window.Array.from(args)):
|
|
||||||
original.call(this);
|
|
||||||
registerDOMRect(originalValue, notify, window, prefs);
|
|
||||||
return originalValue;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return Object.getOwnPropertyDescriptor(temp, "rootBounds").get;
|
return Object.getOwnPropertyDescriptor(temp, "rootBounds").get;
|
||||||
@ -295,15 +263,9 @@
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
function getStatus(obj, status, prefs){
|
|
||||||
status = Object.create(status);
|
|
||||||
status.active = prefs("protectDOMRect", status.url);
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
setProperties(scope.changedFunctions, scope.changedGetters, {
|
setProperties(scope.changedFunctions, scope.changedGetters, {
|
||||||
type: "readout",
|
type: "readout",
|
||||||
getStatus: getStatus,
|
getStatus: getStatusByFlag("protectDOMRect"),
|
||||||
api: "domRect"
|
api: "domRect"
|
||||||
});
|
});
|
||||||
}());
|
}());
|
@ -12,7 +12,7 @@
|
|||||||
scope = require.register("./modifiedHistoryAPI", {});
|
scope = require.register("./modifiedHistoryAPI", {});
|
||||||
}
|
}
|
||||||
|
|
||||||
const {checkerWrapper} = require("./modifiedAPIFunctions");
|
const {checkerWrapper, setGetterProperties} = require("./modifiedAPIFunctions");
|
||||||
|
|
||||||
scope.changedGetters = [
|
scope.changedGetters = [
|
||||||
{
|
{
|
||||||
@ -47,9 +47,9 @@
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
scope.changedGetters.forEach(function(changedGetter){
|
setGetterProperties(scope.changedGetters, {
|
||||||
changedGetter.type = "readout";
|
type: "readout",
|
||||||
changedGetter.getStatus = getStatus;
|
getStatus: getStatus,
|
||||||
changedGetter.api = "history";
|
api: "history"
|
||||||
});
|
});
|
||||||
}());
|
}());
|
@ -12,7 +12,7 @@
|
|||||||
scope = require.register("./modifiedNavigatorAPI", {});
|
scope = require.register("./modifiedNavigatorAPI", {});
|
||||||
}
|
}
|
||||||
|
|
||||||
const {checkerWrapper} = require("./modifiedAPIFunctions");
|
const {checkerWrapper, setGetterProperties, getStatusByFlag} = require("./modifiedAPIFunctions");
|
||||||
const navigator = require("./navigator");
|
const navigator = require("./navigator");
|
||||||
|
|
||||||
scope.changedGetters = navigator.allProperties.map(function(property){
|
scope.changedGetters = navigator.allProperties.map(function(property){
|
||||||
@ -38,15 +38,9 @@
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
function getStatus(obj, status, prefs){
|
setGetterProperties(scope.changedGetters, {
|
||||||
status = Object.create(status);
|
type: "readout",
|
||||||
status.active = prefs("protectNavigator", status.url);
|
getStatus: getStatusByFlag("protectNavigator"),
|
||||||
return status;
|
api: "navigator"
|
||||||
}
|
|
||||||
|
|
||||||
scope.changedGetters.forEach(function(changedGetter){
|
|
||||||
changedGetter.type = "readout";
|
|
||||||
changedGetter.getStatus = getStatus;
|
|
||||||
changedGetter.api = "navigator";
|
|
||||||
});
|
});
|
||||||
}());
|
}());
|
@ -12,7 +12,7 @@
|
|||||||
scope = require.register("./modifiedScreenAPI", {});
|
scope = require.register("./modifiedScreenAPI", {});
|
||||||
}
|
}
|
||||||
|
|
||||||
const {checkerWrapper} = require("./modifiedAPIFunctions");
|
const {checkerWrapper, setGetterProperties, getStatusByFlag} = require("./modifiedAPIFunctions");
|
||||||
|
|
||||||
const physical = {
|
const physical = {
|
||||||
width: Math.round(window.screen.width * window.devicePixelRatio),
|
width: Math.round(window.screen.width * window.devicePixelRatio),
|
||||||
@ -280,15 +280,9 @@
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
function getStatus(obj, status, prefs){
|
setGetterProperties(scope.changedGetters, {
|
||||||
status = Object.create(status);
|
type: "readout",
|
||||||
status.active = prefs("protectScreen", status.url);
|
getStatus: getStatusByFlag("protectScreen"),
|
||||||
return status;
|
api: "screen"
|
||||||
}
|
|
||||||
|
|
||||||
scope.changedGetters.forEach(function(changedGetter){
|
|
||||||
changedGetter.type = "readout";
|
|
||||||
changedGetter.getStatus = getStatus;
|
|
||||||
changedGetter.api = "screen";
|
|
||||||
});
|
});
|
||||||
}());
|
}());
|
@ -12,7 +12,7 @@
|
|||||||
scope = require.register("./modifiedWindowAPI", {});
|
scope = require.register("./modifiedWindowAPI", {});
|
||||||
}
|
}
|
||||||
|
|
||||||
const {checkerWrapper} = require("./modifiedAPIFunctions");
|
const {checkerWrapper, setGetterProperties, getStatusByFlag} = require("./modifiedAPIFunctions");
|
||||||
|
|
||||||
const windowNames = new WeakMap();
|
const windowNames = new WeakMap();
|
||||||
scope.changedGetters = [
|
scope.changedGetters = [
|
||||||
@ -23,10 +23,7 @@
|
|||||||
const temp = {
|
const temp = {
|
||||||
get opener(){
|
get opener(){
|
||||||
return checkerWrapper(checker, this, arguments, function(args, check){
|
return checkerWrapper(checker, this, arguments, function(args, check){
|
||||||
const {prefs, notify, window, original} = check;
|
const {notify, window, original} = check;
|
||||||
if (!prefs("protectWindow", window.location)){
|
|
||||||
return original.apply(this, window.Array.from(args));
|
|
||||||
}
|
|
||||||
const originalOpener = original.apply(this, window.Array.from(args));
|
const originalOpener = original.apply(this, window.Array.from(args));
|
||||||
if (originalOpener !== null){
|
if (originalOpener !== null){
|
||||||
notify("fakedWindowReadout");
|
notify("fakedWindowReadout");
|
||||||
@ -51,10 +48,7 @@
|
|||||||
const temp = {
|
const temp = {
|
||||||
get name(){
|
get name(){
|
||||||
return checkerWrapper(checker, this, arguments, function(args, check){
|
return checkerWrapper(checker, this, arguments, function(args, check){
|
||||||
const {prefs, notify, window, original} = check;
|
const {notify, window, original} = check;
|
||||||
if (!prefs("protectWindow", window.location)){
|
|
||||||
return original.apply(this, window.Array.from(args));
|
|
||||||
}
|
|
||||||
const originalName = original.apply(this, window.Array.from(args));
|
const originalName = original.apply(this, window.Array.from(args));
|
||||||
const returnedName = windowNames.get(window) || "";
|
const returnedName = windowNames.get(window) || "";
|
||||||
if (originalName !== returnedName){
|
if (originalName !== returnedName){
|
||||||
@ -78,15 +72,9 @@
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
function getStatus(obj, status, prefs){
|
setGetterProperties(scope.changedGetters, {
|
||||||
status = Object.create(status);
|
type: "readout",
|
||||||
status.active = prefs("protectWindow", status.url);
|
getStatus: getStatusByFlag("protectWindow"),
|
||||||
return status;
|
api: "window"
|
||||||
}
|
|
||||||
|
|
||||||
scope.changedGetters.forEach(function(changedGetter){
|
|
||||||
changedGetter.type = "readout";
|
|
||||||
changedGetter.getStatus = getStatus;
|
|
||||||
changedGetter.api = "window";
|
|
||||||
});
|
});
|
||||||
}());
|
}());
|
@ -15,10 +15,9 @@
|
|||||||
|
|
||||||
const settingDefinitions = require("./settingDefinitions");
|
const settingDefinitions = require("./settingDefinitions");
|
||||||
|
|
||||||
scope.validVersions = [undefined, 0.1, 0.2, 0.3, 0.4, 0.5];
|
scope.validVersions = [undefined, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6];
|
||||||
scope.transitions = {
|
scope.transitions = {
|
||||||
// eslint-disable-next-line no-unused-vars
|
"": function(){
|
||||||
"": function(oldStorage){
|
|
||||||
return {
|
return {
|
||||||
storageVersion: 0.6
|
storageVersion: 0.6
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user