Add support for other leagues

This commit is contained in:
Chandler Swift 2025-01-14 01:33:16 -06:00
parent 048c2eee65
commit ac156d4ba5
Signed by: chandlerswift
GPG key ID: A851D929D52FB93F
3 changed files with 34 additions and 31 deletions

View file

@ -5,6 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<title>Upcoming NHL Games | BannerGen</title> <title>Upcoming NHL Games | BannerGen</title>
<link href="bootstrap.min.css" rel="stylesheet"> <link href="bootstrap.min.css" rel="stylesheet">
<script src="bootstrap.bundle.min.js"></script>
<style> <style>
img { img {
max-width: 100%; max-width: 100%;
@ -32,9 +33,10 @@
Upcoming Games Upcoming Games
</a> </a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown"> <ul class="dropdown-menu" aria-labelledby="navbarDropdown">
<li><a class="dropdown-item" href="upcoming-nhl-games.html?league=hockey/nhl">NHL</a></li> <li><a class="dropdown-item" href="upcoming-games.html?league=hockey/nhl">NHL</a></li>
<li><a class="dropdown-item" href="upcoming-nhl-games.html?league=football/nfl">NFL</a></li> <li><a class="dropdown-item" href="upcoming-games.html?league=baseball/mlb">MLB</a></li>
<li><a class="dropdown-item" href="upcoming-nhl-games.html?league=basketball/nba">NBA</a></li> <li><a class="dropdown-item" href="upcoming-games.html?league=football/nfl">NFL</a></li>
<li><a class="dropdown-item" href="upcoming-games.html?league=basketball/nba">NBA</a></li>
</ul> </ul>
</li> </li>
<li class="nav-item"> <li class="nav-item">
@ -56,6 +58,10 @@
</div> </div>
</body> </body>
<script> <script>
const league_sport = (new URLSearchParams(document.location.search)).get("league") ?? "hockey/nhl";
if (league_sport == "football/nfl") {
alert("Heads up! ESPN tracks NFL dates differently, and as such the datepicker doesn't currently work. This is a known defect.");
}
let dates, current_date_index; let dates, current_date_index;
function populateUpcomingGames(scoreboard_data) { function populateUpcomingGames(scoreboard_data) {
const upcoming_games_div = document.getElementById('upcoming-games'); const upcoming_games_div = document.getElementById('upcoming-games');
@ -84,13 +90,14 @@
document.getElementById('older').disabled = date_index == 0; document.getElementById('older').disabled = date_index == 0;
document.getElementById('current').innerHTML = date; document.getElementById('current').innerHTML = date;
document.getElementById('newer').disabled = date_index == dates.length - 1; document.getElementById('newer').disabled = date_index == dates.length - 1;
const scoreboard_res = await fetch(`https://site.api.espn.com/apis/site/v2/sports/hockey/nhl/scoreboard?dates=${date.replaceAll('-', '')}`); const scoreboard_res = await fetch(`https://site.api.espn.com/apis/site/v2/sports/${league_sport}/scoreboard?dates=${date.replaceAll('-', '')}`);
const scoreboard_data = await scoreboard_res.json(); const scoreboard_data = await scoreboard_res.json();
populateUpcomingGames(scoreboard_data); populateUpcomingGames(scoreboard_data);
} }
(async function(){ (async function(){
const scoreboard_res = await fetch("https://site.api.espn.com/apis/site/v2/sports/hockey/nhl/scoreboard"); const scoreboard_res = await fetch(`https://site.api.espn.com/apis/site/v2/sports/${league_sport}/scoreboard`);
const scoreboard_data = await scoreboard_res.json(); const scoreboard_data = await scoreboard_res.json();
window.data = scoreboard_data;
populateUpcomingGames(scoreboard_data); populateUpcomingGames(scoreboard_data);
dates = scoreboard_data.leagues[0].calendar.map(s => s.split('T')[0]); dates = scoreboard_data.leagues[0].calendar.map(s => s.split('T')[0]);
const date = scoreboard_data.events[0].date.split('T')[0] const date = scoreboard_data.events[0].date.split('T')[0]

View file

@ -5,6 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<title>About | BannerGen</title> <title>About | BannerGen</title>
<link href="static/bootstrap.min.css" rel="stylesheet"> <link href="static/bootstrap.min.css" rel="stylesheet">
<script src="static/bootstrap.bundle.min.js"></script>
</head> </head>
<body> <body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark"> <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
@ -18,23 +19,20 @@
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" aria-current="page" href="./">Home</a> <a class="nav-link" aria-current="page" href="./">Home</a>
</li> </li>
<li class="nav-item"> <li class="nav-item dropdown">
<a class="nav-link" href="static/upcoming-nhl-games.html">Upcoming NHL Games</a> <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Upcoming Games
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
<li><a class="dropdown-item" href="static/upcoming-games.html?league=hockey/nhl">NHL</a></li>
<li><a class="dropdown-item" href="static/upcoming-games.html?league=baseball/mlb">MLB</a></li>
<li><a class="dropdown-item" href="static/upcoming-games.html?league=football/nfl">NFL</a></li>
<li><a class="dropdown-item" href="static/upcoming-games.html?league=basketball/nba">NBA</a></li>
</ul>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link active" href="about.html">About</a> <a class="nav-link active" href="about.html">About</a>
</li> </li>
<!-- <li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Dropdown
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</li> -->
</ul> </ul>
</div> </div>
</div> </div>

View file

@ -5,6 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<title>BannerGen</title> <title>BannerGen</title>
<link href="static/bootstrap.min.css" rel="stylesheet"> <link href="static/bootstrap.min.css" rel="stylesheet">
<script src="static/bootstrap.bundle.min.js"></script>
</head> </head>
<body> <body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark"> <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
@ -18,23 +19,20 @@
<li class="nav-item"> <li class="nav-item">
<a class="nav-link active" aria-current="page" href="./">Home</a> <a class="nav-link active" aria-current="page" href="./">Home</a>
</li> </li>
<li class="nav-item"> <li class="nav-item dropdown">
<a class="nav-link" href="static/upcoming-nhl-games.html">Upcoming NHL Games</a> <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Upcoming Games
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
<li><a class="dropdown-item" href="static/upcoming-games.html?league=hockey/nhl">NHL</a></li>
<li><a class="dropdown-item" href="static/upcoming-games.html?league=baseball/mlb">MLB</a></li>
<li><a class="dropdown-item" href="static/upcoming-games.html?league=football/nfl">NFL</a></li>
<li><a class="dropdown-item" href="static/upcoming-games.html?league=basketball/nba">NBA</a></li>
</ul>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="about.html">About</a> <a class="nav-link" href="about.html">About</a>
</li> </li>
<!-- <li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Dropdown
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</li> -->
</ul> </ul>
</div> </div>
</div> </div>