Browse Source

Fix entry links

master
NGnius (Graham) 4 years ago
parent
commit
0af901ed3e
2 changed files with 28 additions and 19 deletions
  1. +25
    -16
      site/board/board.js
  2. +3
    -3
      site/board/player.js

+ 25
- 16
site/board/board.js View File

@@ -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)


+ 3
- 3
site/board/player.js View File

@@ -8,7 +8,7 @@ function build_player() {
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 tmpEntry = {ID: -42, Rank:"?", BoardURL: "", BoardName:"Loading...", PlayerURL: "/player?id=1", 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"
@@ -62,9 +62,9 @@ function build_entry(entry) {
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("?")
nameAElem.href = "../board/index.html?"+splitUrl.slice(1).join("?")
} else {
nameAElem.href = "/board/"+splitUrl[0]+".html?"+splitUrl.slice(1).join("?")
nameAElem.href = "../board/index.html?"+splitUrl.slice(1).join("?")
}
nameAElem.innerText = entry.BoardName
nameElem.appendChild(nameAElem)


Loading…
Cancel
Save