2020-07-29 10:03:25 +02:00
|
|
|
let __scripts = [];
|
2020-07-29 13:37:08 +02:00
|
|
|
let __afterLoadScripts = [];
|
2020-07-29 10:03:25 +02:00
|
|
|
|
2020-07-29 12:12:16 +02:00
|
|
|
function registerScript(func, pattern = '.*') {
|
|
|
|
__scripts.push({ "function": func, "pattern": pattern });
|
2020-07-29 10:03:25 +02:00
|
|
|
}
|
|
|
|
|
2020-07-29 11:14:38 +02:00
|
|
|
function runScripts(node) {
|
2020-07-29 12:12:16 +02:00
|
|
|
__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-04-25 22:20:26 +02:00
|
|
|
}
|
2020-07-29 10:35:57 +02:00
|
|
|
});
|
|
|
|
});
|
2020-07-29 10:03:25 +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 13:37:08 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
function runAfterLoad(func, pattern = '.*') {
|
|
|
|
__afterLoadScripts.push({ "function": func, "pattern": pattern });
|
|
|
|
}
|
|
|
|
|
|
|
|
document.addEventListener("DOMContentLoaded", event => awaitPageLoaded(), false);
|
|
|
|
|
|
|
|
function awaitPageLoaded() {
|
|
|
|
let preLoader = document.getElementById('preloader');
|
|
|
|
|
|
|
|
if (typeof preLoader === 'undefined') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let loop = setInterval(() => {
|
|
|
|
if (preLoader.style.display === "none") {
|
|
|
|
clearInterval(loop);
|
|
|
|
|
|
|
|
__afterLoadScripts.forEach(script => {
|
|
|
|
if (window.location.pathname.match(script.pattern)) {
|
|
|
|
script.function();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}, 100);
|
|
|
|
}
|