Spaces:
Running
Running
continue
Browse files- index.html +4 -2
- leaderboard.html +98 -0
- script.js +41 -12
- typing-test.html +5 -1
index.html
CHANGED
|
@@ -15,9 +15,11 @@
|
|
| 15 |
<div class="text-center mb-8">
|
| 16 |
<h1 class="text-3xl font-bold text-gray-800">CodeTyper Racer π</h1>
|
| 17 |
<p class="text-gray-600 mt-2">Login to start your coding speed challenge</p>
|
|
|
|
|
|
|
|
|
|
| 18 |
</div>
|
| 19 |
-
|
| 20 |
-
<form id="loginForm" class="space-y-6">
|
| 21 |
<div>
|
| 22 |
<label for="name" class="block text-sm font-medium text-gray-700 mb-1">Full Name</label>
|
| 23 |
<input type="text" id="name" name="name" required
|
|
|
|
| 15 |
<div class="text-center mb-8">
|
| 16 |
<h1 class="text-3xl font-bold text-gray-800">CodeTyper Racer π</h1>
|
| 17 |
<p class="text-gray-600 mt-2">Login to start your coding speed challenge</p>
|
| 18 |
+
<div class="mt-4">
|
| 19 |
+
<a href="leaderboard.html" class="text-blue-600 hover:text-blue-800 transition">View Leaderboard</a>
|
| 20 |
+
</div>
|
| 21 |
</div>
|
| 22 |
+
<form id="loginForm" class="space-y-6">
|
|
|
|
| 23 |
<div>
|
| 24 |
<label for="name" class="block text-sm font-medium text-gray-700 mb-1">Full Name</label>
|
| 25 |
<input type="text" id="name" name="name" required
|
leaderboard.html
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>CodeTyper Racer - Leaderboard</title>
|
| 7 |
+
<link rel="stylesheet" href="style.css">
|
| 8 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 9 |
+
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
|
| 10 |
+
<script src="https://unpkg.com/feather-icons"></script>
|
| 11 |
+
</head>
|
| 12 |
+
<body class="bg-gray-900 text-gray-100 min-h-screen">
|
| 13 |
+
<header class="bg-gray-800 py-4 shadow-lg">
|
| 14 |
+
<div class="container mx-auto px-4 flex justify-between items-center">
|
| 15 |
+
<h1 class="text-xl font-bold">CodeTyper Racer π</h1>
|
| 16 |
+
<a href="index.html" class="flex items-center space-x-1 bg-gray-700 px-3 py-2 rounded-lg hover:bg-gray-600 transition">
|
| 17 |
+
<i data-feather="home"></i>
|
| 18 |
+
<span>Home</span>
|
| 19 |
+
</a>
|
| 20 |
+
</div>
|
| 21 |
+
</header>
|
| 22 |
+
|
| 23 |
+
<main class="container mx-auto px-4 py-8">
|
| 24 |
+
<div class="bg-gray-800 rounded-xl shadow-lg p-6">
|
| 25 |
+
<div class="flex justify-between items-center mb-6">
|
| 26 |
+
<h2 class="text-2xl font-bold">Top Coders</h2>
|
| 27 |
+
<div class="flex space-x-2">
|
| 28 |
+
<button id="refreshBtn" class="bg-blue-600 px-3 py-1 rounded-lg hover:bg-blue-700 transition">
|
| 29 |
+
<i data-feather="refresh-cw"></i>
|
| 30 |
+
</button>
|
| 31 |
+
</div>
|
| 32 |
+
</div>
|
| 33 |
+
|
| 34 |
+
<div class="overflow-x-auto">
|
| 35 |
+
<table class="w-full">
|
| 36 |
+
<thead>
|
| 37 |
+
<tr class="border-b border-gray-700">
|
| 38 |
+
<th class="text-left py-3 px-4">Rank</th>
|
| 39 |
+
<th class="text-left py-3 px-4">Name</th>
|
| 40 |
+
<th class="text-left py-3 px-4">Grade</th>
|
| 41 |
+
<th class="text-left py-3 px-4">Section</th>
|
| 42 |
+
<th class="text-right py-3 px-4">WPM</th>
|
| 43 |
+
<th class="text-right py-3 px-4">Accuracy</th>
|
| 44 |
+
<th class="text-right py-3 px-4">Date</th>
|
| 45 |
+
</tr>
|
| 46 |
+
</thead>
|
| 47 |
+
<tbody id="leaderboardTable">
|
| 48 |
+
<!-- Leaderboard data will be inserted here -->
|
| 49 |
+
</tbody>
|
| 50 |
+
</table>
|
| 51 |
+
</div>
|
| 52 |
+
</div>
|
| 53 |
+
</main>
|
| 54 |
+
|
| 55 |
+
<script src="script.js"></script>
|
| 56 |
+
<script>
|
| 57 |
+
feather.replace();
|
| 58 |
+
|
| 59 |
+
const leaderboardTable = document.getElementById('leaderboardTable');
|
| 60 |
+
const refreshBtn = document.getElementById('refreshBtn');
|
| 61 |
+
|
| 62 |
+
function loadLeaderboard() {
|
| 63 |
+
leaderboardTable.innerHTML = '';
|
| 64 |
+
|
| 65 |
+
// Get leaderboard from local storage
|
| 66 |
+
let leaderboard = JSON.parse(localStorage.getItem('leaderboard')) || [];
|
| 67 |
+
|
| 68 |
+
// Sort by WPM descending
|
| 69 |
+
leaderboard.sort((a, b) => b.wpm - a.wpm);
|
| 70 |
+
|
| 71 |
+
// Display all entries
|
| 72 |
+
leaderboard.forEach((entry, index) => {
|
| 73 |
+
const row = document.createElement('tr');
|
| 74 |
+
row.className = 'border-b border-gray-700 hover:bg-gray-700';
|
| 75 |
+
|
| 76 |
+
const date = new Date(entry.timestamp);
|
| 77 |
+
const formattedDate = date.toLocaleDateString();
|
| 78 |
+
|
| 79 |
+
row.innerHTML = `
|
| 80 |
+
<td class="py-3 px-4">${index + 1}</td>
|
| 81 |
+
<td class="py-3 px-4">${entry.name}</td>
|
| 82 |
+
<td class="py-3 px-4">${entry.gradeLevel}</td>
|
| 83 |
+
<td class="py-3 px-4">${entry.section}</td>
|
| 84 |
+
<td class="py-3 px-4 text-right">${entry.wpm}</td>
|
| 85 |
+
<td class="py-3 px-4 text-right">${entry.accuracy}%</td>
|
| 86 |
+
<td class="py-3 px-4 text-right">${formattedDate}</td>
|
| 87 |
+
`;
|
| 88 |
+
leaderboardTable.appendChild(row);
|
| 89 |
+
});
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
refreshBtn.addEventListener('click', loadLeaderboard);
|
| 93 |
+
|
| 94 |
+
// Load initial data
|
| 95 |
+
loadLeaderboard();
|
| 96 |
+
</script>
|
| 97 |
+
</body>
|
| 98 |
+
</html>
|
script.js
CHANGED
|
@@ -14,7 +14,6 @@ function calculateTypingStats(startTime, endTime, correctChars, totalChars) {
|
|
| 14 |
const accuracy = totalChars > 0 ? Math.round((correctChars / totalChars) * 100) : 0;
|
| 15 |
return { wpm, accuracy, timeElapsed, totalChars };
|
| 16 |
}
|
| 17 |
-
|
| 18 |
// Save result to leaderboard
|
| 19 |
function saveToLeaderboard(result) {
|
| 20 |
const userData = JSON.parse(localStorage.getItem('userData'));
|
|
@@ -22,16 +21,46 @@ function saveToLeaderboard(result) {
|
|
| 22 |
|
| 23 |
let leaderboard = JSON.parse(localStorage.getItem('leaderboard')) || [];
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
localStorage.setItem('leaderboard', JSON.stringify(leaderboard));
|
| 37 |
-
}
|
|
|
|
| 14 |
const accuracy = totalChars > 0 ? Math.round((correctChars / totalChars) * 100) : 0;
|
| 15 |
return { wpm, accuracy, timeElapsed, totalChars };
|
| 16 |
}
|
|
|
|
| 17 |
// Save result to leaderboard
|
| 18 |
function saveToLeaderboard(result) {
|
| 19 |
const userData = JSON.parse(localStorage.getItem('userData'));
|
|
|
|
| 21 |
|
| 22 |
let leaderboard = JSON.parse(localStorage.getItem('leaderboard')) || [];
|
| 23 |
|
| 24 |
+
// Check if user already has an entry and update if new score is higher
|
| 25 |
+
const existingEntryIndex = leaderboard.findIndex(
|
| 26 |
+
entry => entry.name === userData.name &&
|
| 27 |
+
entry.gradeLevel === userData.gradeLevel &&
|
| 28 |
+
entry.section === userData.section
|
| 29 |
+
);
|
| 30 |
+
|
| 31 |
+
if (existingEntryIndex >= 0) {
|
| 32 |
+
// Update only if new score is better
|
| 33 |
+
if (result.wpm > leaderboard[existingEntryIndex].wpm) {
|
| 34 |
+
leaderboard[existingEntryIndex] = {
|
| 35 |
+
...leaderboard[existingEntryIndex],
|
| 36 |
+
wpm: result.wpm,
|
| 37 |
+
accuracy: result.accuracy,
|
| 38 |
+
time: result.timeElapsed,
|
| 39 |
+
chars: result.totalChars,
|
| 40 |
+
timestamp: new Date().toISOString()
|
| 41 |
+
};
|
| 42 |
+
}
|
| 43 |
+
} else {
|
| 44 |
+
// Add new entry
|
| 45 |
+
leaderboard.push({
|
| 46 |
+
name: userData.name,
|
| 47 |
+
gradeLevel: userData.gradeLevel,
|
| 48 |
+
section: userData.section,
|
| 49 |
+
wpm: result.wpm,
|
| 50 |
+
accuracy: result.accuracy,
|
| 51 |
+
time: result.timeElapsed,
|
| 52 |
+
chars: result.totalChars,
|
| 53 |
+
timestamp: new Date().toISOString()
|
| 54 |
+
});
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
// Sort by WPM descending
|
| 58 |
+
leaderboard.sort((a, b) => b.wpm - a.wpm);
|
| 59 |
+
|
| 60 |
+
// Keep only top 100 entries
|
| 61 |
+
if (leaderboard.length > 100) {
|
| 62 |
+
leaderboard = leaderboard.slice(0, 100);
|
| 63 |
+
}
|
| 64 |
|
| 65 |
localStorage.setItem('leaderboard', JSON.stringify(leaderboard));
|
| 66 |
+
}
|
typing-test.html
CHANGED
|
@@ -14,7 +14,11 @@
|
|
| 14 |
<div class="container mx-auto px-4 flex justify-between items-center">
|
| 15 |
<h1 class="text-xl font-bold">CodeTyper Racer π</h1>
|
| 16 |
<div class="flex items-center space-x-4">
|
| 17 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
00:00
|
| 19 |
</div>
|
| 20 |
<button id="leaderboardBtn" class="flex items-center space-x-1 bg-gray-700 px-3 py-2 rounded-lg hover:bg-gray-600 transition">
|
|
|
|
| 14 |
<div class="container mx-auto px-4 flex justify-between items-center">
|
| 15 |
<h1 class="text-xl font-bold">CodeTyper Racer π</h1>
|
| 16 |
<div class="flex items-center space-x-4">
|
| 17 |
+
<a href="leaderboard.html" class="flex items-center space-x-1 bg-gray-700 px-3 py-2 rounded-lg hover:bg-gray-600 transition">
|
| 18 |
+
<i data-feather="award"></i>
|
| 19 |
+
<span>Leaderboard</span>
|
| 20 |
+
</a>
|
| 21 |
+
<div id="timerDisplay" class="bg-gray-700 px-4 py-2 rounded-lg font-mono">
|
| 22 |
00:00
|
| 23 |
</div>
|
| 24 |
<button id="leaderboardBtn" class="flex items-center space-x-1 bg-gray-700 px-3 py-2 rounded-lg hover:bg-gray-600 transition">
|