#9 Added pattern parameter when registering scripts

This commit is contained in:
Serraniel 2020-07-29 12:12:16 +02:00
parent 4cd8c5bf68
commit bbecb5884f
Signed by: Serraniel
GPG key ID: 3690B4E7364525D3

View file

@ -1,11 +1,15 @@
let __scripts = [];
function registerScript(func) {
__scripts.push(func);
function registerScript(func, pattern = '.*') {
__scripts.push({ "function": func, "pattern": pattern });
}
function runScripts(node) {
__scripts.forEach(script => script(node));
__scripts.forEach(script => {
if (window.location.pathname.match(script.pattern)) {
script.function(node);
}
});
}
let observer = new MutationObserver(mutations => {