#19 First fixes after the great merge

This commit is contained in:
Serraniel 2020-09-11 16:41:22 +02:00
parent ad95cdbe0c
commit 1962547d75
Signed by: Serraniel
GPG key ID: 3690B4E7364525D3
4 changed files with 40 additions and 31 deletions

View file

@ -1,22 +1,26 @@
import * as core from '../utils/aniwatchCore';
import * as helper from '../utils/helpers';
let __notificationCount = '';
runAfterLoad(() => {
retrieveLoginStatus();
__notificationCount = getNotificationCount();
displayNotificationsInTitle();
}, ".*");
export function init() {
core.runAfterLoad(() => {
retrieveLoginStatus();
__notificationCount = getNotificationCount();
displayNotificationsInTitle();
}, ".*");
runAfterPathnameChange(() => {
displayNotificationsInTitle();
}, ".*");
core.runAfterPathnameChange(() => {
displayNotificationsInTitle();
}, ".*");
}
function getNotificationCount() {
if (isLoggedIn) {
if (core.isLoggedIn()) {
let menuUserText = document.getElementById('materialize-menu-dropdown').innerText.split('\n')[4];
let notificationCount = menuUserText.split("")[6];
console.log(notificationCount);
let notificationCount = menuUserText.split('')[6];
// If there are no notifications
if (Number.isNaN(parseInt(notificationCount)) || typeof notificationCount === 'undefined') {
if (Number.isNaN(parseInt(notificationCount)) || !helper.assigned(notificationCount)) {
console.warn("NaN or undefined");
return ``; // Otherwise displayNotificationsInTitle() throws undefined again
}
@ -29,10 +33,9 @@ function getNotificationCount() {
function displayNotificationsInTitle() {
console.log(__notificationCount);
if (typeof __notificationCount === 'undefined') {
if (!helper.assigned(__notificationCount)) {
console.error("NoTiFiCaTiOnCoUnT uNdEfInEd!");
}
else {
} else {
document.title = __notificationCount + document.title;
}
}
}

View file

@ -7,6 +7,7 @@ import { initHelpers } from './utils/helpers';
// enhancements
import { init as animeRequests } from './enhancements/animeRequests';
import { init as lists } from './enhancements/lists';
import { init as notifications } from './enhancements/notifications';
import { init as quickSearch } from './enhancements/quickSearch';
// core
@ -18,4 +19,5 @@ initHelpers();
// enhancements
animeRequests();
lists();
notifications();
quickSearch();

View file

@ -72,8 +72,20 @@ function awaitPageLoaded() {
}, 100);
}
function runAfterPathnameChange(func, pattern = '.*') {
__afterPathnameChangeScripts.push({ "function": func, "pattern": pattern});
export function runAfterPathnameChange(func, pattern = '.*') {
__afterPathnameChangeScripts.push({ "function": func, "pattern": pattern });
}
export function isLoggedIn() {
let menu = document.getElementById('materialize-menu-dropdown');
let result = true;
menu.innerText.split('\n').forEach(item => {
if (item === 'Login') {
result = false;
return;
}
});
}
let locationPath = location.pathname;
@ -90,4 +102,4 @@ function awaitPathnameChange() {
script.function();
}
})
}
}

View file

@ -18,6 +18,10 @@ export function onReady(fn) {
}
}
export function assigned(obj) {
return !(typeof obj === 'undefined' || obj === null);
}
function handleKeyDown(event) {
handleKeyToggle(event, true);
}
@ -32,16 +36,4 @@ function handleKeyToggle(event, isPressed) {
} else if (event.key === 'Control') {
isCtrlPressed = isPressed;
}
}
export function retrieveLoginStatus() {
let menu = document.getElementById('materialize-menu-dropdown');
let menuItem = menu.innerText.split('\n')[4];
if (menuItem === 'Login') {
isLoggedIn = false;
console.log(isLoggedIn);
} else if (menuItem.includes('User')) {
isLoggedIn = true;
console.log(isLoggedIn);
}
}