|
|
|
@ -1,41 +1,33 @@
|
|
|
|
|
import * as core from '../utils/aniwatchCore';
|
|
|
|
|
import * as helper from '../utils/helpers';
|
|
|
|
|
|
|
|
|
|
let __notificationCount = '';
|
|
|
|
|
|
|
|
|
|
export function init() {
|
|
|
|
|
core.runAfterLoad(() => {
|
|
|
|
|
retrieveLoginStatus();
|
|
|
|
|
__notificationCount = getNotificationCount();
|
|
|
|
|
displayNotificationsInTitle();
|
|
|
|
|
updateNotificationsInTitle();
|
|
|
|
|
}, ".*");
|
|
|
|
|
|
|
|
|
|
core.runAfterPathnameChange(() => {
|
|
|
|
|
displayNotificationsInTitle();
|
|
|
|
|
console.log('CHANGE')
|
|
|
|
|
updateNotificationsInTitle();
|
|
|
|
|
}, ".*");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getNotificationCount() {
|
|
|
|
|
if (core.isLoggedIn()) {
|
|
|
|
|
let menuUserText = document.getElementById('materialize-menu-dropdown').innerText.split('\n')[4];
|
|
|
|
|
let notificationCount = menuUserText.split('')[6];
|
|
|
|
|
// If there are no notifications
|
|
|
|
|
if (Number.isNaN(parseInt(notificationCount)) || !helper.assigned(notificationCount)) {
|
|
|
|
|
console.warn("NaN or undefined");
|
|
|
|
|
return ``; // Otherwise displayNotificationsInTitle() throws undefined again
|
|
|
|
|
}
|
|
|
|
|
// Notifications present
|
|
|
|
|
else {
|
|
|
|
|
return `(${notificationCount}) `;
|
|
|
|
|
}
|
|
|
|
|
console.log(menuUserText);
|
|
|
|
|
let notificationCount = menuUserText.match(/\d+/)?.[0] ?? 0;
|
|
|
|
|
console.log(notificationCount);
|
|
|
|
|
return notificationCount;
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function displayNotificationsInTitle() {
|
|
|
|
|
console.log(__notificationCount);
|
|
|
|
|
if (!helper.assigned(__notificationCount)) {
|
|
|
|
|
console.error("NoTiFiCaTiOnCoUnT uNdEfInEd!");
|
|
|
|
|
} else {
|
|
|
|
|
document.title = __notificationCount + document.title;
|
|
|
|
|
function updateNotificationsInTitle() {
|
|
|
|
|
let count = getNotificationCount();
|
|
|
|
|
|
|
|
|
|
if (helper.assigned(count) && count > 0) {
|
|
|
|
|
document.title = `(${count}) ${document.title}`;
|
|
|
|
|
}
|
|
|
|
|
}
|
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.