AniwatchPlus/utils/aniwatchCore.js

23 lines
507 B
JavaScript
Raw Normal View History

let __scripts = [];
2020-07-29 10:35:57 +02:00
function registerScript(func) {
__scripts.push(func);
}
2020-07-29 11:14:38 +02:00
function runScripts(node) {
__scripts.forEach(script => script(node));
}
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
});