Skip to content

Commit

Permalink
update script for reading scores
Browse files Browse the repository at this point in the history
  • Loading branch information
neokat committed Jul 31, 2024
1 parent 64959e8 commit 86ad96b
Showing 1 changed file with 197 additions and 146 deletions.
343 changes: 197 additions & 146 deletions altater.html
Original file line number Diff line number Diff line change
@@ -1,155 +1,206 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta property="og:title" content="Exodus Altater Cup Leaderboard">
<meta property="og:description" content="How do you stack up to other potatoes?">
<meta property="og:url" content="https://neokat.github.io/altater">
<title>Exodus Altater Cup Leaderboard</title>

<link rel="icon" href="https://i.imgur.com/VtISIr7.png " type="image/x-icon">

<style>
html, body {
overflow-x: hidden;
}
body {
background-image: url("https://i.imgur.com/Q1ImfNW.png");
background-repeat: repeat;
}
#spuds {
font-family: Verdana, Helvetica, sans-serif;
border-collapse: collapse;
width: 85%;
}

#spuds td, #spuds th {
border: 1px solid #4f4f4f;
padding: 8px;
text-align: right !important;
}

#spuds tr:nth-child(even) {
background-color: #f2f2f2;
}
#spuds tr:nth-child(odd) {
background-color: #d9d9d9;
}


#spuds th {
padding-top: 12px;
padding-bottom: 12px;
text-align: left;
background-color: #F8AE28;
color: white;
}

@media only screen and (max-width: 730px) {
#spuds td:nth-child(3),
#spuds th:nth-child(3),
#spuds td:nth-child(4),
#spuds th:nth-child(4),
#spuds td:nth-child(5),
#spuds th:nth-child(5),
#spuds td:nth-child(6),
#spuds th:nth-child(6),
#spuds td:nth-child(7),
#spuds th:nth-child(7) {display: none;}
}
</style>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta property="og:title" content="Exodus Altater Cup Leaderboard">
<meta property="og:description" content="How do you stack up to other potatoes?">
<meta property="og:url" content="https://neokat.github.io/altater">
<title>Exodus Altater Cup Leaderboard</title>

<link rel="icon" href="https://i.imgur.com/VtISIr7.png " type="image/x-icon">

<style>
html, body {
overflow-x: hidden;
}

body {
background-image: url("https://i.imgur.com/Q1ImfNW.png");
background-repeat: repeat;
}

#spuds {
font-family: Verdana, Helvetica, sans-serif;
border-collapse: collapse;
width: 85%;
}

#spuds td, #spuds th {
border: 1px solid #4f4f4f;
padding: 8px;
text-align: right !important;
}

#spuds tr:nth-child(even) {
background-color: #f2f2f2;
}

#spuds tr:nth-child(odd) {
background-color: #d9d9d9;
}


#spuds th {
padding-top: 12px;
padding-bottom: 12px;
text-align: left;
background-color: #F8AE28;
color: white;
}

@media only screen and (max-width: 730px) {
#spuds td:nth-child(3),
#spuds th:nth-child(3),
#spuds td:nth-child(4),
#spuds th:nth-child(4),
#spuds td:nth-child(5),
#spuds th:nth-child(5),
#spuds td:nth-child(6),
#spuds th:nth-child(6),
#spuds td:nth-child(7),
#spuds th:nth-child(7) {
display: none;
}
}
</style>
</head>
<body>
<center>
<img src="http://i.imgur.com/oUSxtvh.png" width="60%"><br>
<table id="spuds">
<tr><th id="lu" colspan="9" style="text-align: center !important;"></th></tr>
<tr>
<th style="text-align: center !important;">
TEAM</th>
<th>
USERNAME</th>
<th>
YYB WINS</th>
<th>
YYB DRAWS</th>
<th>
SLSL PLAYS</th>
<th>
MSN PLAYS</th>
<th>
SOSD PLAYS</th>
<th>
TOTAL POINTS</th>
<th>
RANK</th>
</tr>
<tr><td><img src="https://images.neopets.com/altador/altadorcup/2010/popups/maraqua/logo.png" height="50px"></td><td>testjfklsdjflkds</td><td>770</td><td>0</td><td>117</td><td>5,418</td><td>6,020</td><td>21,380</td><td>All-Star</td></tr>

</table>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js">
// build table body
$(function() {
var scores = [];

$.getJSON('scores.json', function(data) {
$.each(data.scores, function(i, user) {
var tblRow = "<tr>" +
"<td><img src=\"" + user.team_logo + "\" height=\"50px\"</td>" +
"<td>" + user.username + "</td>" +
"<td>" + user.yyb_wins + "</td>" +
"<td>" + user.yyb_draws + "</td>" +
"<td>" + user.slsl_wins + "</td>" +
"<td>" + user.msn_plays + "</td>" +
"<td>" + user.sosd_plays + "</td>" +
"<td>" + user.total_score + "</td>" +
"<td>" + user.rank + "</td>" +
"<td>" + user.last_updated + "</td>" +
"</tr>"
$(tblRow).appendTo("#spuds tbody");
});
});

});

// calculate last update time
var seconds = 1000;
var minutes = seconds * 60;
var hours = minutes * 60;
var days = hours * 24;
var now = new Date();
var update = new Date('Tue, 30 Jul 2024 11:57:00 -0500');
var t = now - update;
var w = Math.floor(t / seconds);
var x = Math.floor(t / minutes);
var y = Math.floor(t / hours);
var z = Math.floor(t / days);

if (w == 1) {
document.getElementById("lu").innerHTML = 'Last update: ' + w + ' second ago';
}
if (2 <= w && w < 60) {
document.getElementById("lu").innerHTML = 'Last update: ' + w + ' seconds ago';
}
if (60 <= w && w < 120) {
document.getElementById("lu").innerHTML = 'Last update: ' + x + ' minute ago';
}
if (120 <= w && w < 3600) {
document.getElementById("lu").innerHTML = 'Last update: ' + x + ' minutes ago';
}
if (3600 <= w && w < 7200) {
document.getElementById("lu").innerHTML = 'Last update: ' + y + ' hour ago';
}
if (7200 <= w && w < 86400) {
document.getElementById("lu").innerHTML = 'Last update: ' + y + ' hours ago';
}
if (86400 <= w && w < 172800) {
document.getElementById("lu").innerHTML = 'Last update: ' + z + ' day ago';
}
if (172800 <= w) {
document.getElementById("lu").innerHTML = 'Last update: ' + z + ' days ago';
}
</script>
<img src="http://i.imgur.com/oUSxtvh.png" width="60%"><br>
<table id="spuds">
<!-- <tr>-->
<!-- <th id="lu" colspan="9" style="text-align: center !important;"></th>-->
<!-- </tr>-->
<thead>
<tr>
<th>TEAM</th>
<th>USERNAME</th>
<th>YYB WINS</th>
<th>YYB DRAWS</th>
<th>SLSL PLAYS</th>
<th>MSN PLAYS</th>
<th>SOSD PLAYS</th>
<th>TOTAL POINTS</th>
<th>RANK</th>
</tr>
</thead>
<tbody>
<!-- Data will be populated here -->
</tbody>

</table>
<script>
// build table body

document.addEventListener('DOMContentLoaded', function () {
fetch('scores.json')
.then(response => response.json())
.then(data => {
const scoresTableBody = document.getElementById('spuds').getElementsByTagName('tbody')[0];

data.scores.forEach(score => {
const row = scoresTableBody.insertRow();

const cellTeamLogo = row.insertCell();
const img = document.createElement('img');
img.src = score.team_logo;
cellTeamLogo.appendChild(img);

const cellUsername = row.insertCell();
cellUsername.textContent = score.username;

const cellYybWins = row.insertCell();
cellYybWins.textContent = score.yyb_wins;

const cellYybDraws = row.insertCell();
cellYybDraws.textContent = score.yyb_draws;

const cellSlslGames = row.insertCell();
cellSlslGames.textContent = score.slsl_wins;

const cellMsnPlays = row.insertCell();
cellMsnPlays.textContent = score.msn_plays;

const cellSosdPlays = row.insertCell();
cellSosdPlays.textContent = score.sosd_plays;

const cellTotalScore = row.insertCell();
cellTotalScore.textContent = score.total_score;

const cellRank = row.insertCell();
cellRank.textContent = score.rank;

const cellLastUpdated = row.insertCell();
cellLastUpdated.textContent = score.last_updated;
});
})
.catch(error => {
console.error('Error fetching the JSON data:', error);
});
});

// trash this
// $(function () {
// var scores = [];
//
// $.getJSON('scores.json', function (data) {
// $.each(data.scores, function (i, user) {
// var tblRow = "<tr>" +
// "<td><img src=\"" + user.team_logo + "\" height=\"50px\"</td>" +
// "<td>" + user.username + "</td>" +
// "<td>" + user.yyb_wins + "</td>" +
// "<td>" + user.yyb_draws + "</td>" +
// "<td>" + user.slsl_wins + "</td>" +
// "<td>" + user.msn_plays + "</td>" +
// "<td>" + user.sosd_plays + "</td>" +
// "<td>" + user.total_score + "</td>" +
// "<td>" + user.rank + "</td>" +
// "<td>" + user.last_updated + "</td>" +
// "</tr>"
// $(tblRow).appendTo("#spuds tbody");
// });
// });
//
// });

// // calculate last update time
// var seconds = 1000;
// var minutes = seconds * 60;
// var hours = minutes * 60;
// var days = hours * 24;
// var now = new Date();
// var update = new Date('Tue, 30 Jul 2024 11:57:00 -0500');
// var t = now - update;
// var w = Math.floor(t / seconds);
// var x = Math.floor(t / minutes);
// var y = Math.floor(t / hours);
// var z = Math.floor(t / days);
//
// if (w == 1) {
// document.getElementById("lu").innerHTML = 'Last update: ' + w + ' second ago';
// }
// if (2 <= w && w < 60) {
// document.getElementById("lu").innerHTML = 'Last update: ' + w + ' seconds ago';
// }
// if (60 <= w && w < 120) {
// document.getElementById("lu").innerHTML = 'Last update: ' + x + ' minute ago';
// }
// if (120 <= w && w < 3600) {
// document.getElementById("lu").innerHTML = 'Last update: ' + x + ' minutes ago';
// }
// if (3600 <= w && w < 7200) {
// document.getElementById("lu").innerHTML = 'Last update: ' + y + ' hour ago';
// }
// if (7200 <= w && w < 86400) {
// document.getElementById("lu").innerHTML = 'Last update: ' + y + ' hours ago';
// }
// if (86400 <= w && w < 172800) {
// document.getElementById("lu").innerHTML = 'Last update: ' + z + ' day ago';
// }
// if (172800 <= w) {
// document.getElementById("lu").innerHTML = 'Last update: ' + z + ' days ago';
// }
</script>


</center>
Expand Down

0 comments on commit 86ad96b

Please sign in to comment.