AniwatchPlus/utils/aniwatchCore.js

27 lines
661 B
JavaScript
Raw Normal View History

let __scripts = [];
function registerScript(func, pattern = '.*') {
__scripts.push({ "function": func, "pattern": pattern });
}
2020-07-29 11:14:38 +02:00
function runScripts(node) {
__scripts.forEach(script => {
if (window.location.pathname.match(script.pattern)) {
script.function(node);
}
});
2020-07-29 11:14:38 +02:00
}
2020-07-29 10:35:57 +02:00
let observer = new MutationObserver(mutations => {
mutations.forEach(mutation => {
for (let i = 0; i < mutation.addedNodes.length; i++) {
2020-07-29 11:14:38 +02:00
runScripts(mutation.addedNodes[i]);
}
2020-07-29 10:35:57 +02:00
});
});
2020-07-29 10:35:57 +02:00
observer.observe(document.documentElement || document.body, {
childList: true,
2020-07-29 11:14:38 +02:00
subtree: true,
attributes: true
2020-07-29 10:35:57 +02:00
});