diff --git a/frontend/leaderboard.html b/frontend/leaderboard.html index 932e40f6..977b9ca7 100644 --- a/frontend/leaderboard.html +++ b/frontend/leaderboard.html @@ -187,7 +187,27 @@

Leaderboard

setupPaginationListeners(); fetchLeaderboardData(); // Poll every 2 minutes to detect new syncs - setInterval(fetchLeaderboardData, 2 * 60 * 1000); + // Page Visibility API — pause polling when tab is hidden + let pollInterval; + + function startPolling() { + pollInterval = setInterval(fetchLeaderboardData, 2 * 60 * 1000); + } + + function stopPolling() { + clearInterval(pollInterval); + } + + document.addEventListener("visibilitychange", () => { + if (document.visibilityState === "visible") { + fetchLeaderboardData(); // immediate refresh when tab becomes visible + startPolling(); + } else { + stopPolling(); + } + }); + + startPolling(); }); const leaderboardData = {};