From f6ad9c8aef68e1337a615e18ce612593bfbebecb Mon Sep 17 00:00:00 2001 From: "Tobias Burdow [Kaleidox]" Date: Fri, 20 Oct 2023 20:12:58 +0200 Subject: [PATCH] some connection testing --- docs/index.html | 3 ++- docs/main.js | 47 +++++++++++++++++++++++++++++------------------ 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/docs/index.html b/docs/index.html index 2ef80a88..a4743b09 100644 --- a/docs/index.html +++ b/docs/index.html @@ -29,8 +29,9 @@ -
Minecraft Server Hub
+
Minecraft Server Hub
+

Welcome

diff --git a/docs/main.js b/docs/main.js index 16f6828a..212f51fa 100644 --- a/docs/main.js +++ b/docs/main.js @@ -10,21 +10,16 @@ async function fetchJson(url) { return await (await fetch(url)).json() } -async function load() { - const contentBox = document.querySelector('div.ui-content'); - - function clearContent() { - contentBox.innerHTML = ''; - } +const user = fetchJson('https://api.mc.comroid.org/api/webapp/user'); - // connect to panel or login - async function determineContent() { - let page = urlParams.get('page'); - if (page === undefined || page === null || page === '') - page = 'dash'; - let path = pathPrefix + '/frame/' + page + '.html'; - contentBox.innerHTML = await fetchText(path); - for (const script of document.querySelectorAll('div.ui-content script[type="application/javascript"]')) { +async function determineContent() { + let page = urlParams.get('page'); + if (page === undefined || page === null || page === '') + page = 'dash'; + let path = pathPrefix + '/frame/' + page + '.html'; + contentBox.innerHTML = await fetchText(path); + for (const script of document.querySelectorAll('div.ui-content script[type="application/javascript"]')) { + try { if (evals.includes(page)) continue; let code = null; @@ -33,19 +28,35 @@ async function load() { } else code = script.innerHTML; evals.push(page); eval(code); + } catch (e) { + console.warn('Could not evaluate ' + script+'\n', e); } } +} - // prepare document - function prepareContent() { - for (const container of document.querySelectorAll('b.inject')) { - let expr = container.classList[1]; +function prepareContent() { + for (const container of document.querySelectorAll('b.inject')) { + let expr = container.classList[1]; + try { // noinspection JSPrimitiveTypeWrapperUsage container.innerHTML = new Function('return ' + expr)(); + } catch (e) { + console.warn('Could not evaluate expression "'+expr+'"\n', e); } } +} + +async function load() { + const contentBox = document.querySelector('div.ui-content'); + + function clearContent() { + contentBox.innerHTML = ''; + } + // connect to panel or login await determineContent(); + + // prepare document prepareContent(); }