Spaces:
Running
Running
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Leaderboard - CodeFlow Typing Challenge</title> | |
| <link rel="stylesheet" href="style.css"> | |
| <script src="https://cdn.tailwindcss.com"></script> | |
| <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script> | |
| </head> | |
| <body class="bg-gray-900 text-gray-100 min-h-screen"> | |
| <custom-header></custom-header> | |
| <main class="container mx-auto px-4 py-8 max-w-4xl"> | |
| <div class="text-center mb-12"> | |
| <h1 class="text-4xl font-bold mb-2 text-indigo-400">Leaderboard</h1> | |
| <p class="text-lg text-gray-400">Top typing speeds from our community</p> | |
| </div> | |
| <div class="bg-gray-800 rounded-xl p-6 shadow-lg mb-8"> | |
| <div id="leaderboard-container" class="overflow-x-auto"> | |
| <table class="min-w-full divide-y divide-gray-700"> | |
| <thead> | |
| <tr> | |
| <th class="px-6 py-3 text-left text-xs font-medium text-indigo-300 uppercase tracking-wider">Rank</th> | |
| <th class="px-6 py-3 text-left text-xs font-medium text-indigo-300 uppercase tracking-wider">Name</th> | |
| <th class="px-6 py-3 text-left text-xs font-medium text-indigo-300 uppercase tracking-wider">Grade & Section</th> | |
| <th class="px-6 py-3 text-left text-xs font-medium text-indigo-300 uppercase tracking-wider">Language</th> | |
| <th class="px-6 py-3 text-left text-xs font-medium text-indigo-300 uppercase tracking-wider">WPM</th> | |
| <th class="px-6 py-3 text-left text-xs font-medium text-indigo-300 uppercase tracking-wider">Accuracy</th> | |
| <th class="px-6 py-3 text-left text-xs font-medium text-indigo-300 uppercase tracking-wider">Time</th> | |
| <th class="px-6 py-3 text-left text-xs font-medium text-indigo-300 uppercase tracking-wider">Date</th> | |
| </tr> | |
| </thead> | |
| <tbody id="leaderboard-body" class="divide-y divide-gray-700"> | |
| <!-- Leaderboard data will be inserted here --> | |
| </tbody> | |
| </table> | |
| </div> | |
| </div> | |
| </main> | |
| <custom-footer></custom-footer> | |
| <script src="components/header.js"></script> | |
| <script src="components/footer.js"></script> | |
| <script> | |
| feather.replace(); | |
| // Fetch and display leaderboard | |
| async function loadLeaderboard() { | |
| const leaderboard = await fetchLeaderboard(); | |
| const tbody = document.getElementById('leaderboard-body'); | |
| tbody.innerHTML = ''; | |
| leaderboard.forEach((entry, index) => { | |
| const row = document.createElement('tr'); | |
| row.innerHTML = ` | |
| <td class="px-6 py-4 whitespace-nowrap">${index + 1}</td> | |
| <td class="px-6 py-4 whitespace-nowrap">${entry.name}</td> | |
| <td class="px-6 py-4 whitespace-nowrap">${entry.grade} - ${entry.section}</td> | |
| <td class="px-6 py-4 whitespace-nowrap">${entry.language.toUpperCase()}</td> | |
| <td class="px-6 py-4 whitespace-nowrap">${entry.wpm}</td> | |
| <td class="px-6 py-4 whitespace-nowrap">${entry.accuracy}%</td> | |
| <td class="px-6 py-4 whitespace-nowrap">${entry.time_taken}s</td> | |
| <td class="px-6 py-4 whitespace-nowrap">${new Date(entry.created_at).toLocaleString()}</td> | |
| `; | |
| tbody.appendChild(row); | |
| }); | |
| } | |
| // Call fetchLeaderboard from script.js | |
| async function fetchLeaderboard() { | |
| try { | |
| const response = await fetch('db.php'); | |
| const data = await response.json(); | |
| if (data.success) { | |
| return data.data; | |
| } | |
| return []; | |
| } catch (error) { | |
| console.error('Error fetching leaderboard:', error); | |
| return []; | |
| } | |
| } | |
| document.addEventListener('DOMContentLoaded', loadLeaderboard); | |
| </script> | |
| </body> | |
| </html> |