|
|
|
@ -7,7 +7,6 @@ export function init() {
|
|
|
|
|
}, ".*");
|
|
|
|
|
|
|
|
|
|
core.runAfterPathnameChange(() => {
|
|
|
|
|
console.log('CHANGE')
|
|
|
|
|
updateNotificationsInTitle();
|
|
|
|
|
}, ".*");
|
|
|
|
|
}
|
|
|
|
@ -15,9 +14,7 @@ export function init() {
|
|
|
|
|
function getNotificationCount() {
|
|
|
|
|
if (core.isLoggedIn()) {
|
|
|
|
|
let menuUserText = document.getElementById('materialize-menu-dropdown').innerText.split('\n')[4];
|
|
|
|
|
console.log(menuUserText);
|
|
|
|
|
let notificationCount = menuUserText.match(/\d+/)?.[0] ?? 0;
|
|
|
|
|
console.log(notificationCount);
|
|
|
|
|
return notificationCount;
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
@ -28,6 +25,9 @@ function updateNotificationsInTitle() {
|
|
|
|
|
let count = getNotificationCount();
|
|
|
|
|
|
|
|
|
|
if (helper.assigned(count) && count > 0) {
|
|
|
|
|
document.title = `(${count}) ${document.title}`;
|
|
|
|
|
// document.title is updated after the event is triggered, so we delay our title update by a reasonable time
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
document.title = `(${count}) ${document.title}`;
|
|
|
|
|
}, 100);
|
|
|
|
|
}
|
|
|
|
|
}
|
Getting the NotificationCount on every pushState event increases the chance of it failing. With this solution it fails for every item of the Community and Anime dropdownmenus. With the old solution it failed when inserting the Count into the title for the stats, jobs, seasonal, airing, random, profile, watchlist and notifications. 10 vs 8 pathnames where it doesn't work.
Furthermore with this solution we run into problems on the profile pathname:
We are adding the NotificationCount to the old count whenever we switch from one tab under profile to another; this did not happen with the old solution.
This seems to be related to #42 tho, if you enable Low-end mobile and check the pathnames after visting /home first, you'll see the notification count appear for a while and then disappear once the site is fully shown. With the new solution its definitely because of #42; we are trying to access the menu while the page isn't fully loaded.