diff --git a/enhancements/notifications.js b/enhancements/notifications.js index 2e63723..c6c984f 100644 --- a/enhancements/notifications.js +++ b/enhancements/notifications.js @@ -1,10 +1,21 @@ +let __notificationCount = ''; + runAfterLoad(() => { + __notificationCount = getNotificationCount(); displayNotificationsInTitle(); }, ".*"); -function displayNotificationsInTitle(){ +runAfterPathnameChange(() => { + displayNotificationsInTitle(); +}, ".*"); + +function getNotificationCount() { let menu = document.getElementById('materialize-menu-dropdown'); let menuDropdowns = Array.from(menu.querySelectorAll('ul.dropdown')).slice(-1)[0]; let notificationText = menuDropdowns.innerText.split(" ")[3]; - document.title = notificationText.split(" ")[1] + ' ' + document.title; -} \ No newline at end of file + return notificationText.split(" ")[1] + ' '; +} + +function displayNotificationsInTitle(){ + document.title = __notificationCount + document.title; +} diff --git a/utils/aniwatchCore.js b/utils/aniwatchCore.js index 4552c98..79a67f2 100644 --- a/utils/aniwatchCore.js +++ b/utils/aniwatchCore.js @@ -1,5 +1,7 @@ let __scripts = []; let __afterLoadScripts = []; +let __afterPopstateScripts = []; +let __afterPathnameChangeScripts = []; function registerScript(func, pattern = '.*') { __scripts.push({ "function": func, "pattern": pattern }); @@ -51,4 +53,35 @@ function awaitPageLoaded() { }) } }, 100); -} \ No newline at end of file +} + +function runAfterPathnameChange(func, pattern = '.*') { + __afterPathnameChangeScripts.push({ "function": func, "pattern": pattern}); +} + +let locationPath = location.pathname; +let __loop = setInterval(() => { + if (locationPath != location.pathname) { + locationPath = location.pathname; + awaitPathnameChange(); + } +}, 100); + +function awaitPathnameChange() { + let preLoader = document.getElementById('preloader'); + + if (typeof preLoader === 'undefined') { + return; + } + + let loop = setInterval(() => { + if (preLoader.style.display === "none") { + clearInterval(loop); + __afterPathnameChangeScripts.forEach(script => { + if (window.location.pathname.match(script.pattern)) { + script.function(); + } + }) + } + }, 100); +}