|
- let load_url = "https://exmods.org/load?board=main-test&count=10&start=0";
- let test_url = "http://localhost:1337/load?board=main-test&count=15&start=0";
- //load_url = test_url // testing only
-
- function build_board() {
- let leaderboard = document.getElementById("leaderboard")
- let leaderboard_container = document.getElementById("leaderboard-container")
- let tmpEntry = {ID: -42, Rank:"?", PlayerURL: "", PlayerName: "Loading...", Score:">9000"}
- let errEntry = build_entry(tmpEntry)
- leaderboard.appendChild(errEntry)
- setTimeout(() => {document.getElementById("nameAnchor-42").innerText = "Something went wrong :(";}, 5000) // 5s
- fetch(load_url).then(
- (response) => {
- if (!response.ok || (response.status) != 200) {
- document.getElementById("nameAnchor-42").innerText = "Something went wrong :("
- return
- }
- errEntry.style.display = "none"
- response.json().then(
- (result) => {
- leaderboard.removeChild(errEntry)
- for (entry of result.Items) {
- let newEntry = build_entry(entry)
- // end
- leaderboard.appendChild(newEntry)
- }
- }
- )
- }
- )
- }
-
- function build_entry(entry) {
- let newEntry = document.createElement("div")
- newEntry.setAttribute("id", "entry"+entry.ID)
- newEntry.classList.add("board-entry")
- // rank
- let rankEntry = document.createElement("span")
- rankEntry.setAttribute("id", "rank"+entry.ID)
- rankEntry.innerText = entry.Rank
- rankEntry.classList.add("board-rank")
- newEntry.appendChild(rankEntry)
- // name and url
- let nameElem = document.createElement("span")
- nameElem.setAttribute("id", "name"+entry.ID)
- nameElem.classList.add("board-name")
- let nameAElem = document.createElement("a")
- nameAElem.setAttribute("id", "nameAnchor"+entry.ID)
- nameAElem.classList.add("board-name-a")
- let splitUrl = entry.PlayerURL.split("?")
- if (load_url === test_url) {
- nameAElem.href = "../board"+splitUrl[0]+".html?"+splitUrl.slice(1).join("?")
- } else {
- nameAElem.href = "/board"+splitUrl[0]+".html?"+splitUrl.slice(1).join("?")
- }
- nameAElem.innerText = entry.PlayerName
- nameElem.appendChild(nameAElem)
- newEntry.appendChild(nameElem)
- // score
- let scoreElem = document.createElement("span")
- scoreElem.setAttribute("id", "score"+entry.ID)
- scoreElem.classList.add("board-score")
- scoreElem.innerText = entry.Score
- newEntry.appendChild(scoreElem)
- return newEntry
- }
|