Feature/#19 notifications tab title #31

Merged
kaffem merged 25 commits from feature/#19-notifications-tab-title into develop 2020-10-28 06:46:24 +01:00
Showing only changes of commit 7e44b0d538 - Show all commits

View file

@ -1,5 +1,6 @@
import * as helper from './helpers'; import * as helper from './helpers';
/* SCRIPT LOGICS */
let __scripts = []; let __scripts = [];
let __afterLoadScripts = []; let __afterLoadScripts = [];
let __afterPathnameChangeScripts = []; let __afterPathnameChangeScripts = [];
@ -19,6 +20,9 @@ export function initCore() {
attributes: true attributes: true
}); });
patchBrowser();
window.addEventListener('locationchange', (event) => handleLocationChanged(event));
helper.onReady(() => awaitPageLoaded()); helper.onReady(() => awaitPageLoaded());
} }
@ -72,10 +76,49 @@ function awaitPageLoaded() {
}, 100); }, 100);
} }
/* PATHNAME LOGIC */
export function runAfterPathnameChange(func, pattern = '.*') { export function runAfterPathnameChange(func, pattern = '.*') {
__afterPathnameChangeScripts.push({ "function": func, "pattern": pattern }); __afterPathnameChangeScripts.push({ "function": func, "pattern": pattern });
} }
function handleLocationChanged(event) {
__afterPathnameChangeScripts.forEach(script => {
if (window.location.pathname.match(script.pattern)) {
script.function();
}
});
}
function patchBrowser() {
// patches several browser functions to dispatch a "locationchange" event
// as an extension is not allowed to override these functions we have to inject this as a script tag into the head
let scriptContent = `history.pushState = (func => function pushState() {
let result = func.apply(this, arguments);
window.dispatchEvent(new Event('pushstate'));
window.dispatchEvent(new Event('locationchange'));
return result;
})(history.pushState);
history.replaceState = (func => function replaceState() {
let result = func.apply(this, arguments);
window.dispatchEvent(new Event('replacestate'));
window.dispatchEvent(new Event('locationchange'));
return result;
})(history.replaceState);
window.addEventListener('popstate', () => {
window.dispatchEvent(new Event('locationchange'))
});`
let head = document.getElementsByTagName("head")[0];
let newScript = document.createElement('script');
newScript.type = 'text/javascript';
newScript.innerHTML = scriptContent;
head.appendChild(newScript);
}
/* LOGIN LOGIC */
export function isLoggedIn() { export function isLoggedIn() {
let menu = document.getElementById('materialize-menu-dropdown'); let menu = document.getElementById('materialize-menu-dropdown');
let result = true; let result = true;
@ -89,19 +132,3 @@ export function isLoggedIn() {
kaffem commented 2020-09-14 00:31:54 +02:00 (Migrated from github.com)
Review

I don't quite understand, why you moved this from helpers to core.

I don't quite understand, why you moved this from helpers to core.
Serraniel commented 2020-09-16 21:33:44 +02:00 (Migrated from github.com)
Review

The current helper file more was intended for JS helpers, not website helpers. But I agree that core already also is very mixed up between extension core and aniwatch core. This should be optimized in the feature I think.

The current helper file more was intended for JS helpers, not website helpers. But I agree that core already also is very mixed up between extension core and aniwatch core. This should be optimized in the feature I think.
Serraniel commented 2020-10-25 22:02:10 +01:00 (Migrated from github.com)
Review

This also fixes #42 .

This also fixes #42 .
return result; return result;
} }
let locationPath = location.pathname;
let __loop = setInterval(() => {
if (locationPath != location.pathname) {
locationPath = location.pathname;
awaitPathnameChange();
}
}, 100);
function awaitPathnameChange() {
__afterPathnameChangeScripts.forEach(script => {
if (window.location.pathname.match(script.pattern)) {
script.function();
}
})
}