From 9fe2668c3afec7a4b100cffc9ae722d1baa13fe7 Mon Sep 17 00:00:00 2001 From: kaffem <29717789+kaffem@users.noreply.github.com> Date: Thu, 20 Aug 2020 17:47:00 +0200 Subject: [PATCH] #19 Added checks for notifications --- enhancements/notifications.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/enhancements/notifications.js b/enhancements/notifications.js index e91f6e5..daeb1e2 100644 --- a/enhancements/notifications.js +++ b/enhancements/notifications.js @@ -13,10 +13,26 @@ runAfterPathnameChange(() => { function getNotificationCount() { if (isLoggedIn) { let menuUserText = document.getElementById('materialize-menu-dropdown').innerText.split('\n')[4]; - return menuUserText.split(" ")[1] + ' '; + let notificationCount = menuUserText.split("")[6]; + console.log(notificationCount); + // If there are no notifications + if (Number.isNaN(parseInt(notificationCount)) || typeof notificationCount === 'undefined') { + console.warn("NaN or undefined"); + return ``; // Otherwise displayNotificationsInTitle() throws undefined again + } + // Notifications present + else { + return `(${notificationCount}) `; + } } } -function displayNotificationsInTitle(){ - document.title = __notificationCount + document.title; +function displayNotificationsInTitle() { + console.log(__notificationCount); + if (typeof __notificationCount === 'undefined') { + console.error("NoTiFiCaTiOnCoUnT uNdEfInEd!"); + } + else { + document.title = __notificationCount + document.title; + } }