1
0
Fork 0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2025-07-04 20:46:39 +02:00

Remove code duplications and cleanup

This commit is contained in:
kkapsner 2019-12-10 15:07:22 +01:00
parent 8e414becf0
commit 32f9ea7447
9 changed files with 58 additions and 117 deletions

View file

@ -12,7 +12,7 @@
scope = require.register("./modifiedWindowAPI", {});
}
const {checkerWrapper} = require("./modifiedAPIFunctions");
const {checkerWrapper, setGetterProperties, getStatusByFlag} = require("./modifiedAPIFunctions");
const windowNames = new WeakMap();
scope.changedGetters = [
@ -23,10 +23,7 @@
const temp = {
get opener(){
return checkerWrapper(checker, this, arguments, function(args, check){
const {prefs, notify, window, original} = check;
if (!prefs("protectWindow", window.location)){
return original.apply(this, window.Array.from(args));
}
const {notify, window, original} = check;
const originalOpener = original.apply(this, window.Array.from(args));
if (originalOpener !== null){
notify("fakedWindowReadout");
@ -51,10 +48,7 @@
const temp = {
get name(){
return checkerWrapper(checker, this, arguments, function(args, check){
const {prefs, notify, window, original} = check;
if (!prefs("protectWindow", window.location)){
return original.apply(this, window.Array.from(args));
}
const {notify, window, original} = check;
const originalName = original.apply(this, window.Array.from(args));
const returnedName = windowNames.get(window) || "";
if (originalName !== returnedName){
@ -78,15 +72,9 @@
}
];
function getStatus(obj, status, prefs){
status = Object.create(status);
status.active = prefs("protectWindow", status.url);
return status;
}
scope.changedGetters.forEach(function(changedGetter){
changedGetter.type = "readout";
changedGetter.getStatus = getStatus;
changedGetter.api = "window";
setGetterProperties(scope.changedGetters, {
type: "readout",
getStatus: getStatusByFlag("protectWindow"),
api: "window"
});
}());