diff --git a/enhancements/quickSearch.js b/enhancements/quickSearch.js index 8468276..212e7aa 100644 --- a/enhancements/quickSearch.js +++ b/enhancements/quickSearch.js @@ -33,9 +33,6 @@ function initSearch() { // register focus hotkey document.addEventListener('keypress', event => handleSearchForShiftF(event)); - - // additionally, the last dropdown ul has a "right: 0px" style, which has to be fixed with auto, otherwhise it will pop up in the wrong position - Array.from(menu.querySelectorAll('ul.dropdown')).slice(-1)[0].style.right = 'auto'; } function handleQuickSearch(event) { @@ -47,7 +44,6 @@ function handleQuickSearch(event) { url.pathname = '/search'; url.searchParams.append('q', quickSearchElement.value); - // clicking the link; we are not setting window.location because this will trigger a complete reload of the site linkElement.href = `${url.pathname}${url.search}`; linkElement.click(); diff --git a/utils/aniwatchCore.js b/utils/aniwatchCore.js index 4552c98..1951dc7 100644 --- a/utils/aniwatchCore.js +++ b/utils/aniwatchCore.js @@ -27,16 +27,34 @@ observer.observe(document.documentElement || document.body, { attributes: true }); +function findPreloader() { + return document.getElementById('preloader'); +} + function runAfterLoad(func, pattern = '.*') { - __afterLoadScripts.push({ "function": func, "pattern": pattern }); + let preloader = findPreloader(); + if (typeof preloader !== undefined && preloader.style.display !== "none") { + __afterLoadScripts.push({ "function": func, "pattern": pattern }); + } else { + func(); + } } document.addEventListener("DOMContentLoaded", event => awaitPageLoaded(), false); function awaitPageLoaded() { - let preLoader = document.getElementById('preloader'); + let preLoader = findPreloader(); + + let runScripts = () => { + __afterLoadScripts.forEach(script => { + if (window.location.pathname.match(script.pattern)) { + script.function(); + } + }); + }; if (typeof preLoader === 'undefined') { + runScripts(); return; } @@ -44,11 +62,7 @@ function awaitPageLoaded() { if (preLoader.style.display === "none") { clearInterval(loop); - __afterLoadScripts.forEach(script => { - if (window.location.pathname.match(script.pattern)) { - script.function(); - } - }) + runScripts(); } }, 100); } \ No newline at end of file