Add player list

This commit is contained in:
Daniel Flanagan 2023-11-06 20:04:11 -06:00
parent 6dd8d36f57
commit ac1f03bec0
Signed by: lytedev
GPG key ID: 5B2020A0F9921EF4

View file

@ -35,6 +35,7 @@ function checkMinecraftServerStatus() {
loading.style.display = "none";
servers.style.display = "inherit";
const newChildren = [];
let pl = null;
for (let k of Object.keys(statuses)) {
const status = statuses[k]
const el = document.createElement("li")
@ -50,6 +51,23 @@ function checkMinecraftServerStatus() {
p.style.marginLeft = "0.5em";
if (status.players) {
p.textContent = `(${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)
el.appendChild(pl)
for (let p of status.players.list) {
const pi = document.createElement("li")
pi.textContent = p.name
plist.appendChild(pi)
}
}
}
el.replaceChildren(
s,
@ -57,8 +75,8 @@ function checkMinecraftServerStatus() {
c,
p,
)
if (pl != null) el.appendChild(pl)
newChildren.push(el)
}
servers.replaceChildren(...newChildren)
})