site.lyte.dev/content/minecraft-server-status.md

91 lines
3.6 KiB
Markdown
Raw Permalink Normal View History

2022-02-01 16:41:04 -06:00
---
title: Minecraft Server Status Checker
2023-09-20 09:37:57 -05:00
toc: false
aliases:
/ourcraft-status
2022-02-01 16:41:04 -06:00
---
2023-11-06 17:19:44 -06:00
<noscript>
2022-02-01 16:41:04 -06:00
<p>
2023-11-06 17:19:44 -06:00
It looks like you have javascript disabled! This page uses javascript to query a third-party server which fetches data from our minecraft servers.
2022-02-01 16:41:04 -06:00
</p>
2023-11-06 17:19:44 -06:00
</noscript>
<button id="check-minecraft-server-status">Reload</button>
2022-02-01 16:41:04 -06:00
2023-11-06 17:19:44 -06:00
<div id="server-status">
<p id="server-status-loading">
Checking minecraft servers' status...
</p>
<ul id="servers">
2022-02-01 16:41:04 -06:00
</ul>
</div>
<script>
2023-11-06 17:19:44 -06:00
function checkMinecraftServerStatus() {
const loading = document.getElementById("server-status-loading")
const servers = document.getElementById("servers")
2022-02-01 16:41:04 -06:00
2023-11-06 17:19:44 -06:00
loading.style.display = "inherit";
servers.style.display = "none";
try {
2024-05-07 00:57:09 -05:00
fetch("https://deno-deploy-private.deno.dev/minecraft-server-status").then(res => {
2023-11-06 17:19:44 -06:00
res.json().then(statuses => {
console.log(statuses)
loading.style.display = "none";
servers.style.display = "inherit";
const newChildren = [];
for (let k of Object.keys(statuses)) {
2023-11-07 11:21:26 -06:00
let pl = null;
2023-11-06 17:19:44 -06:00
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) {
2023-11-07 14:43:28 -06:00
p.textContent = ` with ${status.players.online}/${status.players.max} players`
2023-11-06 20:04:11 -06:00
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)
}
}
2023-11-07 14:43:28 -06:00
} else {
p.textContent = ` with ??/?? players`
2022-02-15 13:29:19 -06:00
}
2023-11-06 17:19:44 -06:00
el.replaceChildren(
s,
document.createTextNode(": "),
c,
p,
)
2023-11-06 20:04:11 -06:00
if (pl != null) el.appendChild(pl)
2023-11-06 17:19:44 -06:00
newChildren.push(el)
2022-02-01 16:41:04 -06:00
}
2023-11-06 17:19:44 -06:00
servers.replaceChildren(...newChildren)
})
}).catch(err => console.error(err))
} catch (err) {
console.err(err)
2022-02-01 16:41:04 -06:00
}
}
2023-11-06 17:19:44 -06:00
document.getElementById("check-minecraft-server-status").addEventListener("click", checkMinecraftServerStatus)
document.addEventListener("DOMContentLoaded", checkMinecraftServerStatus)
2022-02-01 16:41:04 -06:00
</script>