~starkingdoms/starkingdoms

ref: 12effd077bf8caf4d4f1cb5d15a8562df0e73be7 starkingdoms/client/dist/index.js -rw-r--r-- 1.4 KiB
12effd07 — core actually remove it instead of crashing 2 years ago
                                                                                
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
import "./modulepreload-polyfill-6303fcb0.js";
let s = "http://localhost:8080", r = [];
function i(e) {
  return e.endsWith("/") ? e + "ping" : e + "/ping";
}
function a(e) {
  let t = new URL(e);
  return t.protocol === "https:" ? "wss://" + t.host + "/ws" : "ws://" + t.host + "/ws";
}
function u(e) {
  fetch(i(e)).then((t) => {
    t.json().then((o) => {
      let l = document.createElement("option");
      l.value = a(e), l.text = `${o.description} - ${o.version.name} - ${o.players} online`, document.getElementById("server").appendChild(l);
    });
  });
}
fetch(`${s}/server-list`).then((e) => {
  e.json().then((t) => {
    r = t.servers;
    for (let o = 0; o < r.length; o++)
      u(r[o]);
  });
});
let n = new URLSearchParams(window.location.search);
n.has("token") && n.has("user") && (window.localStorage.setItem("token", n.get("token")), window.localStorage.setItem("user", n.get("user")));
window.localStorage.getItem("token") !== null && window.localStorage.getItem("user") !== null && (document.getElementById("logout").style.setProperty("display", "block"), document.getElementById("logout").addEventListener("click", () => {
  window.localStorage.clear(), window.location.reload();
}), document.getElementById("loginstatus").innerText = `Logged in! (you are ${window.localStorage.getItem("user")})`);
document.getElementById("login").href = `${s}/select-realm`;