diff --git a/public/assets/js/index.js b/public/assets/js/index.js index 2989935..8e8c972 100644 --- a/public/assets/js/index.js +++ b/public/assets/js/index.js @@ -85,6 +85,8 @@ function showIntro() { displayLaTeXInBody(); $("#container").show(); + + loadTopScoresThisMonth(); } function endGame() { @@ -344,6 +346,46 @@ async function loadLeaderboard(timeRange) { } } +async function loadTopScoresThisMonth() { + const leaderboardSection = $("#leaderboard-section"); + leaderboardSection.empty(); + + try { + let query = db.collection('leaderboard'); + + // Add time constraints for the current month + const now = new Date(); + const startOfMonth = new Date(now.getFullYear(), now.getMonth(), 1); + query = query.where('timestamp', '>=', startOfMonth); + + const snapshot = await query.orderBy('score', 'desc').limit(5).get(); + + if (snapshot.empty) { + leaderboardSection.append('
No scores yet!
'); + return; + } + + leaderboardSection.append('Error loading top scores
'); + } +} + // Start by showing the intro. $(document).ready(function() { // Handlers