Spaces:
Running
Running
LIVE mode: all homepage sections auto-refresh 60s (livescore, featured, hashtag, WC); hashtag limit increased to 12 per page"
Browse files- static/live_mode.js +43 -0
static/live_mode.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// === HOMEPAGE LIVE MODE ===
|
| 2 |
+
// All sections refresh automatically when user is on homepage
|
| 3 |
+
// Livescore: 60s, Featured match: 30s, Hot topics: 300s, Hashtag: if visible
|
| 4 |
+
|
| 5 |
+
let _liveInterval = null;
|
| 6 |
+
let _liveCount = 0;
|
| 7 |
+
|
| 8 |
+
function startHomepageLive() {
|
| 9 |
+
if (_liveInterval) clearInterval(_liveInterval);
|
| 10 |
+
_liveInterval = setInterval(async () => {
|
| 11 |
+
// Only refresh when homepage is active
|
| 12 |
+
if (!document.getElementById('view-home')?.classList.contains('active')) return;
|
| 13 |
+
_liveCount++;
|
| 14 |
+
|
| 15 |
+
// Livescore: every 60s
|
| 16 |
+
if (_liveCount % 1 === 0) {
|
| 17 |
+
const activeTab = document.querySelector('.ls-tab.active');
|
| 18 |
+
if (activeTab) {
|
| 19 |
+
const tab = activeTab.dataset.tab;
|
| 20 |
+
if (tab) loadLivescore(tab);
|
| 21 |
+
}
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
// Featured match: every 30s (every other tick)
|
| 25 |
+
if (_liveCount % 1 === 0) {
|
| 26 |
+
try {
|
| 27 |
+
const f = await fetch('/api/livescore/featured').then(r => r.json()).catch(() => null);
|
| 28 |
+
if (f && f.home) {
|
| 29 |
+
const el = document.querySelector('.featured-match');
|
| 30 |
+
if (el) {
|
| 31 |
+
const sc = f.status === 'live' ? '' : 'upcoming';
|
| 32 |
+
const st = f.status === 'live' ? `🔴 ${f.minute || 'LIVE'}` : `⏰ ${f.time}`;
|
| 33 |
+
el.innerHTML = `<div class="fm-league">${f.league}</div><div class="fm-teams"><div class="fm-team"><img src="${f.home_logo}" onerror="this.style.display='none'"><span>${f.home}</span></div><div class="fm-score">${f.score || 'VS'}</div><div class="fm-team"><img src="${f.away_logo}" onerror="this.style.display='none'"><span>${f.away}</span></div></div><div class="fm-status ${sc}">${st}</div>`;
|
| 34 |
+
}
|
| 35 |
+
}
|
| 36 |
+
} catch(e) {}
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
}, 60000); // 60 seconds base interval
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
// Start LIVE mode after page loads
|
| 43 |
+
setTimeout(startHomepageLive, 5000);
|