diff --git a/utils/aniwatchCore.js b/utils/aniwatchCore.js index fb7587a..4552c98 100644 --- a/utils/aniwatchCore.js +++ b/utils/aniwatchCore.js @@ -1,4 +1,5 @@ let __scripts = []; +let __afterLoadScripts = []; function registerScript(func, pattern = '.*') { __scripts.push({ "function": func, "pattern": pattern }); @@ -24,4 +25,30 @@ observer.observe(document.documentElement || document.body, { childList: true, subtree: true, attributes: true -}); \ No newline at end of file +}); + +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); +} \ No newline at end of file