mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2024-12-22 12:50:36 +01:00
Remove duplicated code
This commit is contained in:
parent
64b60c834a
commit
6fbb9339a1
@ -176,5 +176,18 @@
|
||||
}
|
||||
};
|
||||
|
||||
scope.waitSync = function waitSync(reason = "for no reason"){
|
||||
logging.message(`Starting synchronous request ${reason}.`);
|
||||
try {
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", "https://[::]", false);
|
||||
xhr.send();
|
||||
xhr = null;
|
||||
}
|
||||
catch (error){
|
||||
logging.verbose("Error in XHR:", error);
|
||||
}
|
||||
};
|
||||
|
||||
Object.seal(scope);
|
||||
}());
|
@ -157,19 +157,22 @@
|
||||
};
|
||||
|
||||
const getChannelDataAlreadyFakedArrays = new WeakMap();
|
||||
function fakeArrayCheckerCallback(array, fakeFunction, args, check){
|
||||
const {prefs, notify, window, original} = check;
|
||||
notify("fakedAudioReadout");
|
||||
const ret = original.call(this, ...args);
|
||||
fakeFunction(array, window, prefs);
|
||||
return ret;
|
||||
}
|
||||
// changed functions and their fakes
|
||||
scope.changedFunctions = {
|
||||
getFloatFrequencyData: {
|
||||
object: ["AnalyserNode"],
|
||||
fakeGenerator: function(checker){
|
||||
return function getFloatFrequencyData(array){
|
||||
return checkerWrapper(checker, this, arguments, function(args, check){
|
||||
const {prefs, notify, window, original} = check;
|
||||
notify("fakedAudioReadout");
|
||||
const ret = original.call(this, ...args);
|
||||
fakeFloat32Array(array, window, prefs);
|
||||
return ret;
|
||||
});
|
||||
return checkerWrapper(checker, this, arguments,
|
||||
fakeArrayCheckerCallback.bind(this, array, fakeFloat32Array)
|
||||
);
|
||||
};
|
||||
}
|
||||
},
|
||||
@ -177,13 +180,9 @@
|
||||
object: ["AnalyserNode"],
|
||||
fakeGenerator: function(checker){
|
||||
return function getByteFrequencyData(array){
|
||||
return checkerWrapper(checker, this, arguments, function(args, check){
|
||||
const {prefs, notify, window, original} = check;
|
||||
notify("fakedAudioReadout");
|
||||
const ret = original.call(this, ...args);
|
||||
fakeUint8Array(array, window, prefs);
|
||||
return ret;
|
||||
});
|
||||
return checkerWrapper(checker, this, arguments,
|
||||
fakeArrayCheckerCallback.bind(this, array, fakeUint8Array)
|
||||
);
|
||||
};
|
||||
}
|
||||
},
|
||||
@ -191,13 +190,9 @@
|
||||
object: ["AnalyserNode"],
|
||||
fakeGenerator: function(checker){
|
||||
return function getFloatTimeDomainData(array){
|
||||
return checkerWrapper(checker, this, arguments, function(args, check){
|
||||
const {prefs, notify, window, original} = check;
|
||||
notify("fakedAudioReadout");
|
||||
const ret = original.call(this, ...args);
|
||||
fakeFloat32Array(array, window, prefs);
|
||||
return ret;
|
||||
});
|
||||
return checkerWrapper(checker, this, arguments,
|
||||
fakeArrayCheckerCallback.bind(this, array, fakeFloat32Array)
|
||||
);
|
||||
};
|
||||
}
|
||||
},
|
||||
@ -205,13 +200,9 @@
|
||||
object: ["AnalyserNode"],
|
||||
fakeGenerator: function(checker){
|
||||
return function getByteTimeDomainData(array){
|
||||
return checkerWrapper(checker, this, arguments, function(args, check){
|
||||
const {prefs, notify, window, original} = check;
|
||||
notify("fakedAudioReadout");
|
||||
const ret = original.call(this, ...args);
|
||||
fakeUint8Array(array, window, prefs);
|
||||
return ret;
|
||||
});
|
||||
return checkerWrapper(checker, this, arguments,
|
||||
fakeArrayCheckerCallback.bind(this, array, fakeUint8Array)
|
||||
);
|
||||
};
|
||||
}
|
||||
},
|
||||
|
@ -13,7 +13,7 @@
|
||||
}
|
||||
|
||||
const {checkerWrapper, setGetterProperties, getStatusByFlag} = require("./modifiedAPIFunctions");
|
||||
const logging = require("./logging");
|
||||
const extension = require("./extension");
|
||||
const navigator = require("./navigator");
|
||||
|
||||
let cookieStoreId = false;
|
||||
@ -27,16 +27,7 @@
|
||||
};
|
||||
function getCookieStoreId(){
|
||||
while (cookieStoreId === false){
|
||||
logging.message("Starting synchronous request to wait for cookie store id.");
|
||||
try {
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", "https://[::]", false);
|
||||
xhr.send();
|
||||
xhr = null;
|
||||
}
|
||||
catch (error){
|
||||
logging.verbose("Error in XHR:", error);
|
||||
}
|
||||
extension.waitSync("to wait for cookie store id");
|
||||
}
|
||||
return cookieStoreId;
|
||||
}
|
||||
|
@ -123,16 +123,7 @@
|
||||
|
||||
return function getPersistentRnd(window){
|
||||
while (cookieStoreId === false){
|
||||
logging.message("Starting synchronous request to wait for cookie store id.");
|
||||
try {
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", "https://[::]", false);
|
||||
xhr.send();
|
||||
xhr = null;
|
||||
}
|
||||
catch (error){
|
||||
logging.verbose("Error in XHR:", error);
|
||||
}
|
||||
extension.waitSync("to wait for cookie store id");
|
||||
}
|
||||
const domain = cookieStoreId + getDomain(window);
|
||||
if (!persistentRnd[domain]){
|
||||
|
@ -13,6 +13,7 @@
|
||||
}
|
||||
|
||||
const logging = require("./logging");
|
||||
const extension = require("./extension");
|
||||
const settingDefinitions = require("./settingDefinitions");
|
||||
const settingContainers = require("./settingContainers");
|
||||
const definitionsByName = {};
|
||||
@ -450,16 +451,7 @@
|
||||
};
|
||||
scope.forceLoad = function(){
|
||||
while (settings.isStillDefault){
|
||||
logging.message("Starting synchronous request to wait for settings.");
|
||||
try {
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", "https://[::]", false);
|
||||
xhr.send();
|
||||
xhr = null;
|
||||
}
|
||||
catch (error){
|
||||
logging.verbose("Error in XHR:", error);
|
||||
}
|
||||
extension.waitSync("to wait for settings");
|
||||
logging.message("settings still default?", settings.isStillDefault);
|
||||
}
|
||||
};
|
||||
|
@ -42,42 +42,27 @@
|
||||
|
||||
const urlSettings = {};
|
||||
|
||||
(oldStorage.blackList || "").split(",")
|
||||
[
|
||||
{listName: "blackList", property: "blockMode", value: "block"},
|
||||
{listName: "whiteList", property: "blockMode", value: "allow"},
|
||||
{listName: "ignoreList", property: "showNotifications", value: false}
|
||||
].forEach(function(listAction){
|
||||
(oldStorage[listAction.listName] || "").split(",")
|
||||
.map(function(url){return url.trim();})
|
||||
.filter(function(url){return !!url;})
|
||||
.forEach(function(url){
|
||||
let entry = urlSettings[url];
|
||||
if (!entry){
|
||||
entry = {url, blockMode: "block"};
|
||||
urlSettings[url] = entry;
|
||||
newStorage.urlSettings.push(entry);
|
||||
}
|
||||
});
|
||||
(oldStorage.whiteList || "").split(",")
|
||||
.map(function(url){return url.trim();})
|
||||
.filter(function(url){return !!url;})
|
||||
.forEach(function(url){
|
||||
let entry = urlSettings[url];
|
||||
if (!entry){
|
||||
entry = {url, blockMode: "allow"};
|
||||
urlSettings[url] = entry;
|
||||
newStorage.urlSettings.push(entry);
|
||||
}
|
||||
});
|
||||
(oldStorage.ignoreList || "").split(",")
|
||||
.map(function(url){return url.trim();})
|
||||
.filter(function(url){return !!url;})
|
||||
.forEach(function(url){
|
||||
let entry = urlSettings[url];
|
||||
if (!entry){
|
||||
entry = {url, showNotifications: false};
|
||||
entry = {url, [listAction.property]: listAction.value};
|
||||
urlSettings[url] = entry;
|
||||
newStorage.urlSettings.push(entry);
|
||||
}
|
||||
else {
|
||||
entry.showNotifications = false;
|
||||
entry[listAction.property] = listAction.value;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
["whiteList", "blackList", "ignoreList"].forEach(function(list){
|
||||
if (oldStorage.hasOwnProperty(list)){
|
||||
newStorage[list] = "";
|
||||
|
Loading…
x
Reference in New Issue
Block a user