#19 First fixes after the great merge
This commit is contained in:
parent
ad95cdbe0c
commit
1962547d75
|
@ -1,22 +1,26 @@
|
||||||
|
import * as core from '../utils/aniwatchCore';
|
||||||
|
import * as helper from '../utils/helpers';
|
||||||
|
|
||||||
let __notificationCount = '';
|
let __notificationCount = '';
|
||||||
|
|
||||||
runAfterLoad(() => {
|
export function init() {
|
||||||
retrieveLoginStatus();
|
core.runAfterLoad(() => {
|
||||||
__notificationCount = getNotificationCount();
|
retrieveLoginStatus();
|
||||||
displayNotificationsInTitle();
|
__notificationCount = getNotificationCount();
|
||||||
}, ".*");
|
displayNotificationsInTitle();
|
||||||
|
}, ".*");
|
||||||
|
|
||||||
runAfterPathnameChange(() => {
|
core.runAfterPathnameChange(() => {
|
||||||
displayNotificationsInTitle();
|
displayNotificationsInTitle();
|
||||||
}, ".*");
|
}, ".*");
|
||||||
|
}
|
||||||
|
|
||||||
function getNotificationCount() {
|
function getNotificationCount() {
|
||||||
if (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];
|
let notificationCount = menuUserText.split('')[6];
|
||||||
console.log(notificationCount);
|
|
||||||
// If there are no notifications
|
// 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");
|
console.warn("NaN or undefined");
|
||||||
return ``; // Otherwise displayNotificationsInTitle() throws undefined again
|
return ``; // Otherwise displayNotificationsInTitle() throws undefined again
|
||||||
}
|
}
|
||||||
|
@ -29,10 +33,9 @@ function getNotificationCount() {
|
||||||
|
|
||||||
function displayNotificationsInTitle() {
|
function displayNotificationsInTitle() {
|
||||||
console.log(__notificationCount);
|
console.log(__notificationCount);
|
||||||
if (typeof __notificationCount === 'undefined') {
|
if (!helper.assigned(__notificationCount)) {
|
||||||
console.error("NoTiFiCaTiOnCoUnT uNdEfInEd!");
|
console.error("NoTiFiCaTiOnCoUnT uNdEfInEd!");
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
document.title = __notificationCount + document.title;
|
document.title = __notificationCount + document.title;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -7,6 +7,7 @@ import { initHelpers } from './utils/helpers';
|
||||||
// enhancements
|
// enhancements
|
||||||
import { init as animeRequests } from './enhancements/animeRequests';
|
import { init as animeRequests } from './enhancements/animeRequests';
|
||||||
import { init as lists } from './enhancements/lists';
|
import { init as lists } from './enhancements/lists';
|
||||||
|
import { init as notifications } from './enhancements/notifications';
|
||||||
import { init as quickSearch } from './enhancements/quickSearch';
|
import { init as quickSearch } from './enhancements/quickSearch';
|
||||||
|
|
||||||
// core
|
// core
|
||||||
|
@ -18,4 +19,5 @@ initHelpers();
|
||||||
// enhancements
|
// enhancements
|
||||||
animeRequests();
|
animeRequests();
|
||||||
lists();
|
lists();
|
||||||
|
notifications();
|
||||||
quickSearch();
|
quickSearch();
|
|
@ -72,8 +72,20 @@ function awaitPageLoaded() {
|
||||||
}, 100);
|
}, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
function runAfterPathnameChange(func, pattern = '.*') {
|
export function runAfterPathnameChange(func, pattern = '.*') {
|
||||||
__afterPathnameChangeScripts.push({ "function": func, "pattern": 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;
|
let locationPath = location.pathname;
|
||||||
|
@ -90,4 +102,4 @@ function awaitPathnameChange() {
|
||||||
script.function();
|
script.function();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
|
@ -18,6 +18,10 @@ export function onReady(fn) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function assigned(obj) {
|
||||||
|
return !(typeof obj === 'undefined' || obj === null);
|
||||||
|
}
|
||||||
|
|
||||||
function handleKeyDown(event) {
|
function handleKeyDown(event) {
|
||||||
handleKeyToggle(event, true);
|
handleKeyToggle(event, true);
|
||||||
}
|
}
|
||||||
|
@ -32,16 +36,4 @@ function handleKeyToggle(event, isPressed) {
|
||||||
} else if (event.key === 'Control') {
|
} else if (event.key === 'Control') {
|
||||||
isCtrlPressed = isPressed;
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue