|
|
|
@ -275,4 +275,53 @@ function toggle_leaderboard_chart() { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
document.querySelectorAll("button.open-general-graph").forEach(element => element.addEventListener("click", toggle_combined_chart)); |
|
|
|
|
document.querySelectorAll("button.leaderboard-element").forEach(element => element.addEventListener("click", toggle_leaderboard_chart)); |
|
|
|
|
document.querySelectorAll("button.leaderboard-element").forEach(element => element.addEventListener("click", toggle_leaderboard_chart)); |
|
|
|
|
|
|
|
|
|
async function update_leaderboard() { |
|
|
|
|
this.disabled = true; |
|
|
|
|
this.classList.add("button-updating") |
|
|
|
|
let eventSource = new EventSource("./update.php"); |
|
|
|
|
eventSource.addEventListener("progress", e => { |
|
|
|
|
this.style.setProperty("--button-loading-bar-width", `${e.data*100}%`); |
|
|
|
|
}) |
|
|
|
|
eventSource.addEventListener("forbidden", e => { |
|
|
|
|
const currenttime = new Date(); |
|
|
|
|
const updatetime = new Date(e.data); |
|
|
|
|
let timediff = new Date(currenttime - updatetime); |
|
|
|
|
let resttime = new Date(600000 - (currenttime - updatetime)); |
|
|
|
|
window.alert(`Das letzte Update wurde vor ${format_time_minsec(timediff)} durchgeführt. Versuche es in ${format_time_minsec(resttime)} noch einmal`); |
|
|
|
|
reset_button(this); |
|
|
|
|
eventSource.close(); |
|
|
|
|
}) |
|
|
|
|
eventSource.onerror = e => { |
|
|
|
|
window.alert(`Beim Update ist ein Fehler aufgetreten. Versuche es später noch einmal`) |
|
|
|
|
reset_button(this); |
|
|
|
|
eventSource.close(); |
|
|
|
|
} |
|
|
|
|
eventSource.addEventListener("done", e => { |
|
|
|
|
reset_button(this); |
|
|
|
|
eventSource.close(); |
|
|
|
|
}) |
|
|
|
|
function reset_button(button) { |
|
|
|
|
button.disabled = false; |
|
|
|
|
button.style.setProperty("--button-loading-bar-width", `0`); |
|
|
|
|
button.classList.remove("button-updating"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
document.querySelector("button.update-leaderboard").addEventListener("click", update_leaderboard); |
|
|
|
|
|
|
|
|
|
function format_time_minsec(date) { |
|
|
|
|
let format, trenner = "", min = "", nullausgleich = ""; |
|
|
|
|
if (date.getMinutes() === 0) { |
|
|
|
|
format = " Sekunden"; |
|
|
|
|
} else { |
|
|
|
|
min = date.getMinutes(); |
|
|
|
|
format = " Minuten"; |
|
|
|
|
trenner = ":"; |
|
|
|
|
if (date.getSeconds() < 10) { |
|
|
|
|
nullausgleich = "0"; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return min + trenner + nullausgleich + date.getSeconds() + format; |
|
|
|
|
} |