Difference between revisions of "Template:NCAAF"
Jump to navigation
Jump to search
(Created page with "<html> <center> <div id="ncaaf-ticker" style="background:#fff; color:#FF69B4; padding:8px; font: bold 10px Verdana; line-height:1.6; border:1px solid #c8ccd1; overflow:hidden; text-align:center;"> <div id="ncaaf-scores">Loading NCAAF scores...</div> </div> <script> (function() { function updateScores() { console.log('NCAAF: Fetch started'); fetch('https://site.api.espn.com/apis/site/v2/sports/football/college-football/scoreboard?dates=20251122') // Temp: Ye...") |
|||
| Line 4: | Line 4: | ||
<div id="ncaaf-scores">Loading NCAAF scores...</div> | <div id="ncaaf-scores">Loading NCAAF scores...</div> | ||
</div> | </div> | ||
<script> | <script> | ||
(function() { | (function() { | ||
function updateScores() { | function updateScores() { | ||
console.log('NCAAF: Fetch started'); | console.log('NCAAF: Fetch started'); | ||
fetch( | // Dynamic date for today in YYYYMMDD format | ||
const today = new Date().toISOString().slice(0, 10).replace(/-/g, ''); | |||
fetch(`https://site.api.espn.com/apis/site/v2/sports/football/college-football/scoreboard?dates=${today}`) | |||
.then(r => { | .then(r => { | ||
if (!r.ok) throw new Error(`HTTP ${r.status}: ${r.statusText}`); | if (!r.ok) throw new Error(`HTTP ${r.status}: ${r.statusText}`); | ||
| Line 15: | Line 16: | ||
}) | }) | ||
.then(data => { | .then(data => { | ||
console.log('NCAAF: Data received', data); | console.log('NCAAF: Data received', data); // Logs full response for debug | ||
const container = document.getElementById('ncaaf-scores'); | const container = document.getElementById('ncaaf-scores'); | ||
const events = data.events || []; | const events = data.events || []; | ||
console.log(`NCAAF: Found ${events.length} events`); | console.log(`NCAAF: Found ${events.length} events`); | ||
if (events.length === 0) { | if (events.length === 0) { | ||
const | const todayDisplay = new Date().toLocaleDateString(); | ||
container.innerHTML = `<em>No NCAAF games on ${ | container.innerHTML = `<em>No NCAAF games on ${todayDisplay}—check back soon!</em>`; | ||
return; | return; | ||
} | } | ||
const scoresHTML = events.map(event => { | const scoresHTML = events.map(event => { | ||
const c = event.competitions[0]; | const c = event.competitions[0]; | ||
const home = c.competitors.find(t => t.homeAway === 'home'); | const home = c.competitors.find(t => t.homeAway === 'home'); | ||
const away = c.competitors.find(t => t.homeAway === 'away'); | const away = c.competitors.find(t => t.homeAway === 'away'); | ||
// Status handling (uses event-level status as primary fallback) | // Status handling (uses event-level status as primary fallback) | ||
let status = event.status.type.state === 'post' ? 'Final' : | let status = event.status.type.state === 'post' ? 'Final' : | ||
event.status.type.shortDetail || | event.status.type.shortDetail || | ||
(event.status.period > 0 ? `Q${event.status.period} ${event.status.displayClock || ''}`.trim() : ''); | (event.status.period > 0 ? `Q${event.status.period} ${event.status.displayClock || ''}`.trim() : ''); | ||
return `<span style="margin:0 15px; white-space:nowrap;"> | return `<span style="margin:0 15px; white-space:nowrap;"> | ||
${away.team.displayName} ${away.score || 0} – | ${away.team.displayName} ${away.score || 0} – | ||
| Line 42: | Line 41: | ||
</span>`; | </span>`; | ||
}).join(' '); | }).join(' '); | ||
container.innerHTML = scoresHTML; | container.innerHTML = scoresHTML; | ||
}) | }) | ||
| Line 50: | Line 48: | ||
}); | }); | ||
} | } | ||
updateScores(); | updateScores(); | ||
setInterval(updateScores, 60000); // refresh every minute | setInterval(updateScores, 60000); // refresh every minute | ||
Latest revision as of 20:48, 29 November 2025
Loading NCAAF scores...