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

Remove duplicated code

This commit is contained in:
kkapsner 2020-01-26 01:11:18 +01:00
parent 64b60c834a
commit 6fbb9339a1
6 changed files with 59 additions and 96 deletions

View file

@ -41,43 +41,28 @@
};
const urlSettings = {};
(oldStorage.blackList || "").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};
urlSettings[url] = entry;
newStorage.urlSettings.push(entry);
}
else {
entry.showNotifications = false;
}
});
[
{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, [listAction.property]: listAction.value};
urlSettings[url] = entry;
newStorage.urlSettings.push(entry);
}
else {
entry[listAction.property] = listAction.value;
}
});
});
["whiteList", "blackList", "ignoreList"].forEach(function(list){
if (oldStorage.hasOwnProperty(list)){
newStorage[list] = "";