#19 Imporvments in notification logic
This commit is contained in:
parent
7e44b0d538
commit
b1aef75409
|
@ -1,41 +1,33 @@
|
||||||
import * as core from '../utils/aniwatchCore';
|
import * as core from '../utils/aniwatchCore';
|
||||||
import * as helper from '../utils/helpers';
|
import * as helper from '../utils/helpers';
|
||||||
|
|
||||||
let __notificationCount = '';
|
|
||||||
|
|
||||||
export function init() {
|
export function init() {
|
||||||
core.runAfterLoad(() => {
|
core.runAfterLoad(() => {
|
||||||
retrieveLoginStatus();
|
updateNotificationsInTitle();
|
||||||
__notificationCount = getNotificationCount();
|
|
||||||
displayNotificationsInTitle();
|
|
||||||
}, ".*");
|
}, ".*");
|
||||||
|
|
||||||
core.runAfterPathnameChange(() => {
|
core.runAfterPathnameChange(() => {
|
||||||
displayNotificationsInTitle();
|
console.log('CHANGE')
|
||||||
|
updateNotificationsInTitle();
|
||||||
}, ".*");
|
}, ".*");
|
||||||
}
|
}
|
||||||
|
|
||||||
function getNotificationCount() {
|
function getNotificationCount() {
|
||||||
if (core.isLoggedIn()) {
|
if (core.isLoggedIn()) {
|
||||||
let menuUserText = document.getElementById('materialize-menu-dropdown').innerText.split('\n')[4];
|
let menuUserText = document.getElementById('materialize-menu-dropdown').innerText.split('\n')[4];
|
||||||
let notificationCount = menuUserText.split('')[6];
|
console.log(menuUserText);
|
||||||
// If there are no notifications
|
let notificationCount = menuUserText.match(/\d+/)?.[0] ?? 0;
|
||||||
if (Number.isNaN(parseInt(notificationCount)) || !helper.assigned(notificationCount)) {
|
console.log(notificationCount);
|
||||||
console.warn("NaN or undefined");
|
return notificationCount;
|
||||||
return ``; // Otherwise displayNotificationsInTitle() throws undefined again
|
} else {
|
||||||
}
|
return 0;
|
||||||
// Notifications present
|
|
||||||
else {
|
|
||||||
return `(${notificationCount}) `;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function displayNotificationsInTitle() {
|
function updateNotificationsInTitle() {
|
||||||
console.log(__notificationCount);
|
let count = getNotificationCount();
|
||||||
if (!helper.assigned(__notificationCount)) {
|
|
||||||
console.error("NoTiFiCaTiOnCoUnT uNdEfInEd!");
|
if (helper.assigned(count) && count > 0) {
|
||||||
} else {
|
document.title = `(${count}) ${document.title}`;
|
||||||
document.title = __notificationCount + document.title;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue