summaryrefslogtreecommitdiff
path: root/static/js/minecraft.js
diff options
context:
space:
mode:
authorElizabeth Alexander Hunt <me@liz.coffee>2026-06-20 09:40:07 -0700
committerElizabeth Alexander Hunt <me@liz.coffee>2026-06-20 09:40:07 -0700
commitfb653292612eddca5b088ed88466c546d1597107 (patch)
tree900ed32e066812688858ed3bb15128c41bb78054 /static/js/minecraft.js
downloadpenguins.lan-fb653292612eddca5b088ed88466c546d1597107.tar.gz
penguins.lan-fb653292612eddca5b088ed88466c546d1597107.zip
Initial commit
Diffstat (limited to 'static/js/minecraft.js')
-rw-r--r--static/js/minecraft.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/static/js/minecraft.js b/static/js/minecraft.js
new file mode 100644
index 0000000..757053c
--- /dev/null
+++ b/static/js/minecraft.js
@@ -0,0 +1,30 @@
+(function () {
+ const el = document.getElementById("mc-status");
+ if (!el) return;
+
+ function escape(s) {
+ const d = document.createElement("div");
+ d.textContent = s;
+ return d.innerHTML;
+ }
+
+ async function poll() {
+ try {
+ const r = await fetch("/minecraft", { headers: { Accept: "application/json" } });
+ if (!r.ok) return;
+ const s = await r.json();
+ if (!s.online) {
+ el.textContent = "server offline";
+ } else if (s.count === 0) {
+ el.textContent = `online — 0/${s.max} players`;
+ } else {
+ el.innerHTML = `online — ${s.count}/${s.max}: ` + s.players.map(escape).join(", ");
+ }
+ } catch (e) {
+ /* keep the last render */
+ }
+ }
+
+ poll();
+ setInterval(poll, 10000);
+})();