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}`) {
|
||||
|
Reference in New Issue
Block a user