|
|
@@ -1,33 +1,42 @@ |
|
|
|
let load_url = "https://leadercraft.exmods.org/s/load?board=main-test&count=10&start=0"; |
|
|
|
let load_url = "https://leadercraft.exmods.org/s/load"; |
|
|
|
let test_url = "http://localhost:1337/load?board=main-test&count=15&start=0"; |
|
|
|
//load_url = test_url // testing only |
|
|
|
|
|
|
|
let default_args = "?board=main-test&count=50&start=0"; |
|
|
|
let always_args = "&count=50&start=0"; |
|
|
|
|
|
|
|
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( |
|
|
|
let leaderboard = document.getElementById("leaderboard"); |
|
|
|
let leaderboard_container = document.getElementById("leaderboard-container"); |
|
|
|
let tmpEntry = {ID: -42, Rank:"?", PlayerURL: "/player?id=1", PlayerName: "Loading...", Score:">9000"} |
|
|
|
let errEntry = build_entry(tmpEntry); |
|
|
|
leaderboard.appendChild(errEntry); |
|
|
|
let gen_url = load_url; |
|
|
|
if (window.location.href.split("?").length < 2) { // no args |
|
|
|
gen_url += default_args; |
|
|
|
} else { |
|
|
|
gen_url += "?"+window.location.href.split("?").slice(1).join("&")+always_args; |
|
|
|
} |
|
|
|
setTimeout(() => {document.getElementById("nameAnchor-42").innerText = "Something went wrong :(";}, 5000); // 5s |
|
|
|
fetch(gen_url).then( |
|
|
|
(response) => { |
|
|
|
if (!response.ok || (response.status) != 200) { |
|
|
|
document.getElementById("nameAnchor-42").innerText = "Something went wrong :(" |
|
|
|
return |
|
|
|
document.getElementById("nameAnchor-42").innerText = "Something went wrong :("; |
|
|
|
return; |
|
|
|
} |
|
|
|
errEntry.style.display = "none" |
|
|
|
errEntry.style.display = "none"; |
|
|
|
response.json().then( |
|
|
|
(result) => { |
|
|
|
leaderboard.removeChild(errEntry) |
|
|
|
for (entry of result.Items) { |
|
|
|
let newEntry = build_entry(entry) |
|
|
|
let newEntry = build_entry(entry); |
|
|
|
// end |
|
|
|
leaderboard.appendChild(newEntry) |
|
|
|
leaderboard.appendChild(newEntry); |
|
|
|
} |
|
|
|
} |
|
|
|
) |
|
|
|
); |
|
|
|
} |
|
|
|
) |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
function build_entry(entry) { |
|
|
@@ -51,7 +60,7 @@ function build_entry(entry) { |
|
|
|
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.href = "../board"+splitUrl[0]+".html?"+splitUrl.slice(1).join("?") |
|
|
|
} |
|
|
|
nameAElem.innerText = entry.PlayerName |
|
|
|
nameElem.appendChild(nameAElem) |
|
|
|