#19 Fallback for badly loaded pages added

This commit is contained in:
Serraniel 2020-10-25 11:21:48 +01:00
parent a840f644b7
commit f0eebd2803
Signed by: Serraniel
GPG key ID: 3690B4E7364525D3

View file

@ -13,7 +13,22 @@ export function init() {
function getNotificationCount() {
if (core.isLoggedIn()) {
let menuUserText = document.getElementById('materialize-menu-dropdown').innerText.split('\n')[4];
let menus = document.getElementById('materialize-menu-dropdown').innerText.split('\n');
// On some pages there is an issue if the website is loaded using them as entry point (eg. /Search).
// They don´t have their menu build completly directly and the above code does not return the "User" element :/
// If this happens the menu is splitted into many more (~20) items than only 5.
// So if there are more, we just try again later.
// Additionally, if the element is there correctly it´s not updated with the notification count directly, so we wait a bit longer before retrying.
if (menus.length > 5) {
setTimeout(() => {
updateNotificationsInTitle();
}, 2000);
return undefined;
}
let menuUserText = menus[4];
let notificationCount = menuUserText.match(/\d+/)?.[0] ?? 0;
return notificationCount;
} else {