|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- let load_url = "https://exmods.org/player"
- let test_url = "http://localhost:1337/player"
- //load_url = test_url // testing only
-
- function build_player() {
- // build
- let player = document.getElementById("player-name")
- let player_link = document.getElementById("player-link")
- let leaderboard = document.getElementById("leaderboard")
- let leaderboard_container = document.getElementById("leaderboard-container")
- let tmpEntry = {ID: -42, Rank:"?", BoardURL: "", BoardName:"Loading...", PlayerURL: "", PlayerName: "Loading...", Score:">9000"}
- let errEntry = build_entry(tmpEntry)
- leaderboard.appendChild(errEntry)
- let gen_url = load_url+"?"+window.location.href.split("?").slice(1).join("?")+"&entries=10"
- 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
- }
- errEntry.style.display = "none"
- response.json().then(
- (result) => {
- if (result.Items.length!=1) {
- document.getElementById("nameAnchor-42").innerText = "Something went wrong :("
- return
- }
- errEntry.style.display = "none"
- leaderboard.removeChild(errEntry)
- // build player
- player_link.innerText = result.Items[0].Name
- player_link.href = ""// TODO use result.Items[0].Url
- // build leaderboard
- for (entry of result.Items[0].Entries) {
- 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.BoardURL.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.BoardName
- 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
- }
|