document.addEventListener('DOMContentLoaded', () => { new ResultService(); }); class ResultService { hash = 0; alertbox = document.getElementById("alert"); table = document.getElementById("ranking-table"); endpoint = "../api/v1/race/sync.php?h="; constructor() { this.loop(); } async loop() { try { await this.updateTable(); this.alertbox.classList.add("hidden"); } catch (error) { console.log(error); this.alertbox.innerHTML = "Noe gikk galt: " + error; this.alertbox.classList.remove("hidden"); } setTimeout(() => { this.loop(); }, 1000); } async updateTable() { let response = await fetch(this.endpoint + this.hash); if (response.status === 204) { return; } let json = await response.json(); this.hash = json.hash; let data = json.data; let tableHTML = ""; tableHTML += "
Lag | "; tableHTML += "Tid | "; tableHTML += "
---|---|
" + data.map.team.name[element.id] + " | "; tableHTML += "" + element.time + " | "; tableHTML += "