diff options
Diffstat (limited to 'src/spectate/main.ts')
-rw-r--r-- | src/spectate/main.ts | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/spectate/main.ts b/src/spectate/main.ts index 3fcf414..2f6de83 100644 --- a/src/spectate/main.ts +++ b/src/spectate/main.ts @@ -133,6 +133,7 @@ ws.onmessage = message => { d.forEach(k => snakes.delete(k)) } else if ("game" in p) { snakes.clear() + update_stats() size = p.game.width } else if ("win" in p) { const winner = snakes.get(p.win[0])?.name; @@ -165,3 +166,17 @@ function chat(message: string, clas = "chat") { chat_history.splice(0, 1).forEach(e => e.remove()) } } + +async function update_stats() { + const res = await fetch("/stats"); + const scoreboard = await res.json() as [string, number][] + + const sce = document.getElementById("scoreboard_inner")! + sce.innerHTML = "" + + for (const [name, score] of scoreboard) { + const e = document.createElement("li") + e.textContent = `${name}: ${score}` + sce.append(e) + } +} |