91 lines
3.6 KiB
Markdown
91 lines
3.6 KiB
Markdown
---
|
|
title: Minecraft Server Status Checker
|
|
toc: false
|
|
aliases:
|
|
/ourcraft-status
|
|
---
|
|
|
|
<noscript>
|
|
<p>
|
|
It looks like you have javascript disabled! This page uses javascript to query a third-party server which fetches data from our minecraft servers.
|
|
</p>
|
|
</noscript>
|
|
|
|
<button id="check-minecraft-server-status">Reload</button>
|
|
|
|
<div id="server-status">
|
|
<p id="server-status-loading">
|
|
Checking minecraft servers' status...
|
|
</p>
|
|
<ul id="servers">
|
|
</ul>
|
|
</div>
|
|
|
|
<script>
|
|
function checkMinecraftServerStatus() {
|
|
const loading = document.getElementById("server-status-loading")
|
|
const servers = document.getElementById("servers")
|
|
|
|
loading.style.display = "inherit";
|
|
servers.style.display = "none";
|
|
try {
|
|
fetch("https://deno-deploy-private.deno.dev/minecraft-server-status").then(res => {
|
|
res.json().then(statuses => {
|
|
console.log(statuses)
|
|
loading.style.display = "none";
|
|
servers.style.display = "inherit";
|
|
const newChildren = [];
|
|
for (let k of Object.keys(statuses)) {
|
|
let pl = null;
|
|
const status = statuses[k]
|
|
const el = document.createElement("li")
|
|
const s = document.createElement("strong")
|
|
s.textContent = k
|
|
const c = document.createElement("code")
|
|
c.className = "chroma"
|
|
const cs = document.createElement("span")
|
|
c.appendChild(cs)
|
|
cs.className = (status.online ? "na" : "err")
|
|
cs.textContent = status.online ? "ONLINE" : "OFFLINE"
|
|
const p = document.createElement("span")
|
|
if (status.players) {
|
|
p.textContent = ` with ${status.players.online}/${status.players.max} players`
|
|
if (status.players.online > 0 && status.players.list) {
|
|
pl = document.createElement("details")
|
|
pl.style.marginTop = "0"
|
|
const pld = document.createElement("summary")
|
|
pld.textContent = "Players List"
|
|
pld.style.color = "var(--link-fg)"
|
|
pld.style.textDecoration = "underline"
|
|
const plist = document.createElement("ul")
|
|
pl.appendChild(pld)
|
|
pl.appendChild(plist)
|
|
for (let p of status.players.list) {
|
|
const pi = document.createElement("li")
|
|
pi.textContent = p.name
|
|
plist.appendChild(pi)
|
|
}
|
|
}
|
|
} else {
|
|
p.textContent = ` with ??/?? players`
|
|
}
|
|
el.replaceChildren(
|
|
s,
|
|
document.createTextNode(": "),
|
|
c,
|
|
p,
|
|
)
|
|
if (pl != null) el.appendChild(pl)
|
|
newChildren.push(el)
|
|
}
|
|
servers.replaceChildren(...newChildren)
|
|
})
|
|
}).catch(err => console.error(err))
|
|
} catch (err) {
|
|
console.err(err)
|
|
}
|
|
}
|
|
document.getElementById("check-minecraft-server-status").addEventListener("click", checkMinecraftServerStatus)
|
|
document.addEventListener("DOMContentLoaded", checkMinecraftServerStatus)
|
|
</script>
|