#12 Added runAfterLoad in aniwatch Core
This commit is contained in:
parent
0ca4b42431
commit
1b66379515
|
@ -1,4 +1,5 @@
|
||||||
let __scripts = [];
|
let __scripts = [];
|
||||||
|
let __afterLoadScripts = [];
|
||||||
|
|
||||||
function registerScript(func, pattern = '.*') {
|
function registerScript(func, pattern = '.*') {
|
||||||
__scripts.push({ "function": func, "pattern": pattern });
|
__scripts.push({ "function": func, "pattern": pattern });
|
||||||
|
@ -24,4 +25,30 @@ observer.observe(document.documentElement || document.body, {
|
||||||
childList: true,
|
childList: true,
|
||||||
subtree: true,
|
subtree: true,
|
||||||
attributes: true
|
attributes: true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
Loading…
Reference in a new issue