mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-07-04 20:46:39 +02:00
Big linting
This commit is contained in:
parent
b5e6d049ce
commit
aef6bd3d59
58 changed files with 2074 additions and 1856 deletions
|
@ -4,7 +4,7 @@
|
|||
(function(){
|
||||
"use strict";
|
||||
|
||||
var scope;
|
||||
let scope;
|
||||
if ((typeof exports) !== "undefined"){
|
||||
scope = exports;
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
|||
scope.expandContainer = null;
|
||||
|
||||
scope.getUrlValueContainer = function(name, url){
|
||||
var matching = scope.urlContainer.get().filter(function(urlSetting){
|
||||
const matching = scope.urlContainer.get().filter(function(urlSetting){
|
||||
return urlSetting.hasOwnProperty(name);
|
||||
}).filter(function(urlSetting){
|
||||
return urlSetting.match(url);
|
||||
|
@ -32,8 +32,8 @@
|
|||
}
|
||||
};
|
||||
scope.setUrlValue = function(name, value, url){
|
||||
var urlContainerValue = scope.urlContainer.get();
|
||||
var matching = urlContainerValue.filter(function(urlSetting){
|
||||
const urlContainerValue = scope.urlContainer.get();
|
||||
let matching = urlContainerValue.filter(function(urlSetting){
|
||||
return urlSetting.match(url);
|
||||
});
|
||||
if (!matching.length){
|
||||
|
@ -46,8 +46,8 @@
|
|||
return scope.urlContainer.set(urlContainerValue);
|
||||
};
|
||||
scope.resetUrlValue = function(name, url){
|
||||
var urlContainerValue = scope.urlContainer.get();
|
||||
var matching = urlContainerValue.filter(function(urlSetting){
|
||||
let urlContainerValue = scope.urlContainer.get();
|
||||
const matching = urlContainerValue.filter(function(urlSetting){
|
||||
return urlSetting.match(url);
|
||||
});
|
||||
if (matching.length){
|
||||
|
@ -61,6 +61,92 @@
|
|||
}
|
||||
};
|
||||
|
||||
function processHideContainer(settingDefinition){
|
||||
scope.hideContainer = settingDefinition;
|
||||
let changeListeners = {};
|
||||
settingDefinition.setHideByName = function(name, value){
|
||||
logging.verbose("set hide of", name, "to", value);
|
||||
const hideStore = settingDefinition.get();
|
||||
hideStore[name] = value;
|
||||
settingDefinition.set(hideStore);
|
||||
(changeListeners[name] || []).forEach(function(listener){
|
||||
listener(value);
|
||||
});
|
||||
};
|
||||
settingDefinition.getHideByName = function(name){
|
||||
const hideStore = settingDefinition.get();
|
||||
return hideStore[name] || false;
|
||||
};
|
||||
settingDefinition.onHideChange = function(name, listener){
|
||||
if (!changeListeners[name]){
|
||||
changeListeners[name] = [];
|
||||
}
|
||||
changeListeners[name].push(listener);
|
||||
};
|
||||
settingDefinition.on(function(event){
|
||||
const value = event.newValue;
|
||||
Object.keys(value).forEach(function(name){
|
||||
(changeListeners[name] || []).forEach(function(listener){
|
||||
listener(value[name]);
|
||||
});
|
||||
});
|
||||
const oldValue = event.oldValue;
|
||||
Object.keys(oldValue).filter(function(name){
|
||||
return !value.hasOwnProperty(name);
|
||||
}).forEach(function(name){
|
||||
(changeListeners[name] || []).forEach(function(listener){
|
||||
listener(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
settingDefinition.hideAble = false;
|
||||
}
|
||||
|
||||
function processExpandContainer(settingDefinition){
|
||||
scope.expandContainer = settingDefinition;
|
||||
let changeListeners = {};
|
||||
settingDefinition.setExpandByName = function(name, value){
|
||||
logging.verbose("set expand of", name, "to", value);
|
||||
const expandStore = settingDefinition.get();
|
||||
expandStore[name] = value;
|
||||
settingDefinition.set(expandStore);
|
||||
(changeListeners[name] || []).forEach(function(listener){
|
||||
listener(value);
|
||||
});
|
||||
};
|
||||
settingDefinition.getExpandByName = function(name, defaultValue = false){
|
||||
const expandStore = settingDefinition.get();
|
||||
if ((typeof expandStore[name]) !== "undefined"){
|
||||
return expandStore[name] || false;
|
||||
}
|
||||
else {
|
||||
return defaultValue;
|
||||
}
|
||||
};
|
||||
settingDefinition.onExpandChange = function(name, listener){
|
||||
if (!changeListeners[name]){
|
||||
changeListeners[name] = [];
|
||||
}
|
||||
changeListeners[name].push(listener);
|
||||
};
|
||||
settingDefinition.on(function(event){
|
||||
const value = event.newValue;
|
||||
Object.keys(value).forEach(function(name){
|
||||
(changeListeners[name] || []).forEach(function(listener){
|
||||
listener(value[name]);
|
||||
});
|
||||
});
|
||||
const oldValue = event.oldValue;
|
||||
Object.keys(oldValue).filter(function(name){
|
||||
return !value.hasOwnProperty(name);
|
||||
}).forEach(function(name){
|
||||
(changeListeners[name] || []).forEach(function(listener){
|
||||
listener(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
scope.check = function(settingDefinition){
|
||||
if (settingDefinition.isUrlContainer){
|
||||
scope.urlContainer = settingDefinition;
|
||||
|
@ -70,89 +156,11 @@
|
|||
}
|
||||
|
||||
if (settingDefinition.isHideContainer){
|
||||
scope.hideContainer = settingDefinition;
|
||||
let changeListeners = {};
|
||||
settingDefinition.setHideByName = function(name, value){
|
||||
logging.verbose("set hide of", name, "to", value);
|
||||
const hideStore = settingDefinition.get();
|
||||
hideStore[name] = value;
|
||||
settingDefinition.set(hideStore);
|
||||
(changeListeners[name] || []).forEach(function(listener){
|
||||
listener(value);
|
||||
});
|
||||
};
|
||||
settingDefinition.getHideByName = function(name){
|
||||
const hideStore = settingDefinition.get();
|
||||
return hideStore[name] || false;
|
||||
};
|
||||
settingDefinition.onHideChange = function(name, listener){
|
||||
if (!changeListeners[name]){
|
||||
changeListeners[name] = [];
|
||||
}
|
||||
changeListeners[name].push(listener);
|
||||
};
|
||||
settingDefinition.on(function(event){
|
||||
const value = event.newValue;
|
||||
Object.keys(value).forEach(function(name){
|
||||
(changeListeners[name] || []).forEach(function(listener){
|
||||
listener(value[name]);
|
||||
});
|
||||
});
|
||||
const oldValue = event.oldValue;
|
||||
Object.keys(oldValue).filter(function(name){
|
||||
return !value.hasOwnProperty(name);
|
||||
}).forEach(function(name){
|
||||
(changeListeners[name] || []).forEach(function(listener){
|
||||
listener(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
settingDefinition.hideAble = false;
|
||||
processHideContainer(settingDefinition);
|
||||
}
|
||||
|
||||
if (settingDefinition.isExpandContainer){
|
||||
scope.expandContainer = settingDefinition;
|
||||
let changeListeners = {};
|
||||
settingDefinition.setExpandByName = function(name, value){
|
||||
logging.verbose("set expand of", name, "to", value);
|
||||
const expandStore = settingDefinition.get();
|
||||
expandStore[name] = value;
|
||||
settingDefinition.set(expandStore);
|
||||
(changeListeners[name] || []).forEach(function(listener){
|
||||
listener(value);
|
||||
});
|
||||
};
|
||||
settingDefinition.getExpandByName = function(name, defaultValue = false){
|
||||
const expandStore = settingDefinition.get();
|
||||
if ((typeof expandStore[name]) !== "undefined"){
|
||||
return expandStore[name] || false;
|
||||
}
|
||||
else {
|
||||
return defaultValue;
|
||||
}
|
||||
};
|
||||
settingDefinition.onExpandChange = function(name, listener){
|
||||
if (!changeListeners[name]){
|
||||
changeListeners[name] = [];
|
||||
}
|
||||
changeListeners[name].push(listener);
|
||||
};
|
||||
settingDefinition.on(function(event){
|
||||
const value = event.newValue;
|
||||
Object.keys(value).forEach(function(name){
|
||||
(changeListeners[name] || []).forEach(function(listener){
|
||||
listener(value[name]);
|
||||
});
|
||||
});
|
||||
const oldValue = event.oldValue;
|
||||
Object.keys(oldValue).filter(function(name){
|
||||
return !value.hasOwnProperty(name);
|
||||
}).forEach(function(name){
|
||||
(changeListeners[name] || []).forEach(function(listener){
|
||||
listener(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
processExpandContainer(settingDefinition);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -160,8 +168,8 @@
|
|||
if (scope.urlContainer){
|
||||
scope.urlContainer.on(function({newValue, oldValue}){
|
||||
newValue.forEach(function(urlSetting){
|
||||
var regExp;
|
||||
var domain = !!urlSetting.url.match(/^[A-Za-z0-9_.-]+$/);
|
||||
let regExp;
|
||||
const domain = !!urlSetting.url.match(/^[A-Za-z0-9_.-]+$/);
|
||||
if (domain){
|
||||
regExp = new RegExp(
|
||||
"(?:^|\\.)" + urlSetting.url.replace(/([\\+*?[^\]$(){}=!|.])/g, "\\$1") + "\\.?$",
|
||||
|
@ -200,9 +208,9 @@
|
|||
);
|
||||
});
|
||||
|
||||
var newUrls = newValue.map(function(entry){return entry.url;});
|
||||
var oldUrls = oldValue.map(function(entry){return entry.url;});
|
||||
var matching = {};
|
||||
const newUrls = newValue.map(function(entry){return entry.url;});
|
||||
const oldUrls = oldValue.map(function(entry){return entry.url;});
|
||||
const matching = {};
|
||||
newUrls.forEach(function(url, i){
|
||||
matching[url] = {new: i, old: oldUrls.indexOf(url)};
|
||||
});
|
||||
|
@ -212,12 +220,12 @@
|
|||
}
|
||||
});
|
||||
Object.keys(matching).forEach(function(url){
|
||||
var oldEntry = oldValue[matching[url].old] || {};
|
||||
var newEntry = newValue[matching[url].new] || {};
|
||||
const oldEntry = oldValue[matching[url].old] || {};
|
||||
const newEntry = newValue[matching[url].new] || {};
|
||||
scope.urlContainer.entries.forEach(function(settingDefinition){
|
||||
var name = settingDefinition.name;
|
||||
var oldValue = oldEntry[name];
|
||||
var newValue = newEntry[name];
|
||||
const name = settingDefinition.name;
|
||||
const oldValue = oldEntry[name];
|
||||
const newValue = newEntry[name];
|
||||
|
||||
if (oldValue !== newValue){
|
||||
((eventHandler[name] || {})[url] || []).forEach(function(callback){
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue