summaryrefslogtreecommitdiff
path: root/static/js/waddlers.js
blob: d1dbd631d82fe403a6d1e437a45bef5bf545855b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
(function () {
  const roster = document.getElementById("roster");
  if (!roster) return;

  function escape(s) {
    const d = document.createElement("div");
    d.textContent = s;
    return d.innerHTML;
  }

  function render(list) {
    roster.innerHTML = list
      .map(
        (w) =>
          `<li><span class="dot ${w.status}"></span> <strong>${escape(w.username)}</strong> <span class="muted">— last seen ${escape(w.lastSeen)}</span></li>`
      )
      .join("");
  }

  async function poll() {
    try {
      const r = await fetch("/waddlers", { headers: { Accept: "application/json" } });
      if (r.ok) render(await r.json());
    } catch (e) {
      console.error(e);
    }
  }

  setInterval(poll, 2000);
})();