Feature/#19 notifications tab title #31
33
src/javascript/enhancements/notifications.js
Normal file
33
src/javascript/enhancements/notifications.js
Normal file
|
@ -5,6 +5,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 languageDisplay } from './enhancements/languageDisplay';
|
import { init as languageDisplay } from './enhancements/languageDisplay';
|
||||||
|
import { init as notifications } from './enhancements/notifications';
|
||||||
import { init as quickSearch } from './enhancements/quickSearch';
|
import { init as quickSearch } from './enhancements/quickSearch';
|
||||||
|
|
||||||
// core
|
// core
|
||||||
|
@ -16,4 +17,5 @@ initHelpers();
|
||||||
// enhancements
|
// enhancements
|
||||||
animeRequests();
|
animeRequests();
|
||||||
languageDisplay();
|
languageDisplay();
|
||||||
|
notifications();
|
||||||
quickSearch();
|
quickSearch();
|
|
@ -1,7 +1,9 @@
|
||||||
import * as helper from './helpers';
|
import * as helper from './helpers';
|
||||||
|
|
||||||
|
/* SCRIPT LOGICS */
|
||||||
let __scripts = [];
|
let __scripts = [];
|
||||||
let __afterLoadScripts = [];
|
let __afterLoadScripts = [];
|
||||||
|
let __afterLocationChangeScripts = [];
|
||||||
|
|
||||||
export function initCore() {
|
export function initCore() {
|
||||||
let observer = new MutationObserver(mutations => {
|
let observer = new MutationObserver(mutations => {
|
||||||
|
@ -18,6 +20,29 @@ export function initCore() {
|
||||||
attributes: true
|
attributes: true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
runAfterLoad(() => {
|
||||||
|
let loadingBar = document.getElementById('enable-ani-cm');
|
||||||
|
let loadingBarObserver = new MutationObserver(mutations => {
|
||||||
|
mutations.forEach(mutation => {
|
||||||
|
// enable-ani-cm node changes from display:none to display:block after loading
|
||||||
|
if (mutation.oldValue.includes('display: none')) {
|
||||||
|
__afterLocationChangeScripts.forEach(script => {
|
||||||
|
if (window.location.pathname.match(script.pattern)) {
|
||||||
|
script.function();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
loadingBarObserver.observe(loadingBar, {
|
||||||
|
attributes: true,
|
||||||
|
attributeOldValue: true,
|
||||||
|
attributeFilter: ['style'],
|
||||||
|
});
|
||||||
|
|
||||||
|
}, '.*')
|
||||||
|
|
||||||
helper.onReady(() => awaitPageLoaded());
|
helper.onReady(() => awaitPageLoaded());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,10 +88,30 @@ function awaitPageLoaded() {
|
||||||
}
|
}
|
||||||
|
|
||||||
let loop = setInterval(() => {
|
let loop = setInterval(() => {
|
||||||
if (preLoader.style.display === "none") {
|
if (preLoader.style.display === "none" && document.readyState === 'complete') {
|
||||||
clearInterval(loop);
|
clearInterval(loop);
|
||||||
|
|
||||||
runScripts();
|
runScripts();
|
||||||
}
|
}
|
||||||
}, 100);
|
}, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* PATHNAME LOGIC */
|
||||||
|
export function runAfterLocationChange(func, pattern = '.*') {
|
||||||
|
__afterLocationChangeScripts.push({ "function": func, "pattern": pattern });
|
||||||
|
}
|
||||||
|
|
||||||
|
/* LOGIN LOGIC */
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue
Getting the NotificationCount on every pushState event increases the chance of it failing. With this solution it fails for every item of the Community and Anime dropdownmenus. With the old solution it failed when inserting the Count into the title for the stats, jobs, seasonal, airing, random, profile, watchlist and notifications. 10 vs 8 pathnames where it doesn't work.
Furthermore with this solution we run into problems on the profile pathname:
We are adding the NotificationCount to the old count whenever we switch from one tab under profile to another; this did not happen with the old solution.
This seems to be related to #42 tho, if you enable Low-end mobile and check the pathnames after visting /home first, you'll see the notification count appear for a while and then disappear once the site is fully shown. With the new solution its definitely because of #42; we are trying to access the menu while the page isn't fully loaded.