access: Minor JS improvements
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
window.CLIENTS = window.CLIENTS || [];
|
||||
|
||||
function getCredentialsUsername(client) {
|
||||
return window.localStorage.getItem(`${CLIENT}/${client}/username`);
|
||||
}
|
||||
@ -11,7 +13,7 @@ function getCredentialsPassword(client) {
|
||||
function getBasicAuth(client) {
|
||||
return {
|
||||
'Authorization': 'Basic ' + btoa(getCredentialsUsername(client) + ':' + getCredentialsPassword(client)),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
async function _get(client, path) {
|
||||
@ -128,15 +130,9 @@ function render() {
|
||||
const nav = document.getElementsByTagName("nav")[0].getElementsByTagName("ul")[0];
|
||||
for (const li of nav.children) li.className = '';
|
||||
|
||||
let client = null;
|
||||
for (const id in CLIENTS) {
|
||||
if (hash.startsWith(`#/${id}/`) || hash === `#/${id}`) {
|
||||
client = id;
|
||||
}
|
||||
}
|
||||
|
||||
if (client === null) {
|
||||
window.location.hash = `#/${Object.keys(CLIENTS)[0]}`;
|
||||
const client = Object.keys(CLIENTS).find(id => hash.startsWith(`#/${id}/`) || hash === `#/${id}`);
|
||||
if (client === undefined) {
|
||||
window.location.hash = `#/${Object.keys(CLIENTS).find(id => !!getCredentialsUsername(id) && !!getCredentialsPassword(id)) || Object.keys(CLIENTS)[0]}`;
|
||||
return;
|
||||
}
|
||||
nav.children[Object.keys(CLIENTS).indexOf(client)].className = 'active';
|
||||
@ -168,14 +164,8 @@ function render() {
|
||||
|
||||
function update() {
|
||||
const hash = window.location.hash;
|
||||
let client = null;
|
||||
for (const id in CLIENTS) {
|
||||
if (hash.startsWith(`#/${id}/`) || hash === `#/${id}`) {
|
||||
client = id;
|
||||
}
|
||||
}
|
||||
|
||||
if (document.hidden) {
|
||||
const client = Object.keys(CLIENTS).find(id => hash.startsWith(`#/${id}/`) || hash === `#/${id}`);
|
||||
if (document.hidden || client === undefined) {
|
||||
// do nothing
|
||||
} else {
|
||||
if (hash === `#/${client}`) {
|
||||
|
@ -1,5 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
window.ELWIG_API = window.ELWIG_API || null;
|
||||
|
||||
function getCredentialsUsername() {
|
||||
return window.localStorage.getItem(`${CLIENT}/username`);
|
||||
}
|
||||
@ -11,7 +13,7 @@ function getCredentialsPassword() {
|
||||
function getBasicAuth() {
|
||||
return {
|
||||
'Authorization': 'Basic ' + btoa(getCredentialsUsername() + ':' + getCredentialsPassword()),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
async function _get(path) {
|
||||
@ -311,10 +313,6 @@ window.addEventListener('hashchange', () => {
|
||||
render();
|
||||
});
|
||||
|
||||
window.addEventListener('pageshow', update)
|
||||
|
||||
document.addEventListener('visibilitychange', update);
|
||||
|
||||
function actionLogin(form) {
|
||||
window.localStorage.setItem(`${CLIENT}/username`, form.username.value);
|
||||
window.localStorage.setItem(`${CLIENT}/password`, form.password.value);
|
||||
|
Reference in New Issue
Block a user