Skip to content

Commit

Permalink
some connection testing
Browse files Browse the repository at this point in the history
  • Loading branch information
burdoto committed Oct 20, 2023
1 parent 2214699 commit f6ad9c8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
3 changes: 2 additions & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
<script type="application/javascript" src="main.js"></script>
</head>
<body onload="load()" onbeforeunload="unload()">
<div class="ui-menubar"><a href="/">Minecraft Server Hub</b></a></div>
<div class="ui-menubar"><a href="/">Minecraft Server Hub</a></div>
<div class="ui-container-page">
<h3>Welcome <b class="inject user.name"></b></h3>
<div class="ui-content">
<div class="serverStatusUnknown"></div>
</div>
Expand Down
47 changes: 29 additions & 18 deletions docs/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}

Expand Down

0 comments on commit f6ad9c8

Please sign in to comment.