<h1>Live resultater</h1>
<br>
<div id="ranking-table">
</div>
<script>
var hash = 0;
function main()
{
setInterval(function() {
updateTable()
}, 1000);
updateTable();
}
async function updateTable()
let response = await fetch("sync.php?h=" + hash);
if (response.status === 204)
return;
let json = await response.json();
hash = json.hash;
let data = json.data;
let table_html = "";
table_html += "<table>";
table_html += "<tr>";
table_html += "<th>Navn</th>";
table_html += "<th>Runder</th>";
table_html += "<th>Bestetid</th>";
table_html += "</tr>";
data.forEach(element => {
table_html += "<td>" + element.name + "</td>";
table_html += "<td>" + element.rounds + "</td>";
table_html += "<td>" + element.bestTime + "</td>";
});
document.getElementById("ranking-table").innerHTML = table_html;
document.addEventListener('DOMContentLoaded', function() {
main();
</script>