Spaces:
Running
Running
File size: 15,826 Bytes
78ba5af |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Typing Speed Test</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
.typing-text {
background-color: rgba(243, 244, 246, 0.5);
border-radius: 0.5rem;
padding: 1.5rem;
font-size: 1.25rem;
line-height: 1.75rem;
min-height: 150px;
position: relative;
}
.typing-text span {
position: relative;
}
.typing-text span.active {
background-color: #3b82f6;
color: white;
border-radius: 0.25rem;
}
.typing-text span.correct {
color: #10b981;
}
.typing-text span.incorrect {
color: #ef4444;
text-decoration: underline;
}
.timer-progress {
height: 8px;
transition: width 0.1s linear;
}
.result-card {
transform: scale(0.95);
opacity: 0;
transition: all 0.3s ease-out;
}
.result-card.show {
transform: scale(1);
opacity: 1;
}
.typing-input {
opacity: 0;
position: absolute;
left: -9999px;
}
</style>
</head>
<body class="bg-gray-100 min-h-screen flex flex-col items-center justify-center p-4">
<div class="w-full max-w-3xl mx-auto">
<h1 class="text-4xl font-bold text-center text-blue-600 mb-2">
<i class="fas fa-keyboard mr-2"></i>Typing Speed Test
</h1>
<p class="text-center text-gray-600 mb-8">Test your typing speed in different time intervals</p>
<div class="bg-white rounded-xl shadow-lg p-6 mb-6">
<div class="flex flex-wrap justify-center gap-4 mb-6">
<button id="30s" class="time-btn px-6 py-2 rounded-full bg-blue-100 text-blue-600 font-medium hover:bg-blue-200 transition">
<i class="far fa-clock mr-2"></i>30 Seconds
</button>
<button id="45s" class="time-btn px-6 py-2 rounded-full bg-blue-100 text-blue-600 font-medium hover:bg-blue-200 transition">
<i class="far fa-clock mr-2"></i>45 Seconds
</button>
<button id="60s" class="time-btn px-6 py-2 rounded-full bg-blue-100 text-blue-600 font-medium hover:bg-blue-200 transition">
<i class="far fa-clock mr-2"></i>60 Seconds
</button>
</div>
<div class="mb-4 flex justify-between items-center">
<div class="text-gray-600">
<span id="timer" class="text-2xl font-bold text-blue-600">00:00</span>
</div>
<div class="text-gray-600">
<span id="wpm" class="text-2xl font-bold text-blue-600">0</span> WPM
</div>
</div>
<div class="timer-progress bg-gray-200 rounded-full mb-6">
<div id="progress-bar" class="bg-blue-500 rounded-full h-full" style="width: 100%"></div>
</div>
<div class="typing-text mb-6" id="typingText">
Click on a time option above to start the test. The text will appear here when you begin.
</div>
<input type="text" id="typingInput" class="typing-input" autocomplete="off">
<div class="text-center">
<button id="startBtn" class="px-8 py-3 bg-blue-600 text-white font-bold rounded-lg hover:bg-blue-700 transition">
<i class="fas fa-play mr-2"></i>Start Test
</button>
<button id="retryBtn" class="px-8 py-3 bg-gray-200 text-gray-700 font-bold rounded-lg hover:bg-gray-300 transition ml-4 hidden">
<i class="fas fa-redo mr-2"></i>Try Again
</button>
</div>
</div>
<div id="resultCard" class="result-card bg-white rounded-xl shadow-lg p-6 w-full max-w-3xl mx-auto">
<h2 class="text-2xl font-bold text-center text-blue-600 mb-4">Your Results</h2>
<div class="grid grid-cols-1 md:grid-cols-3 gap-6">
<div class="bg-blue-50 p-4 rounded-lg text-center">
<div class="text-4xl font-bold text-blue-600 mb-2" id="resultWPM">0</div>
<div class="text-gray-600">Words Per Minute</div>
</div>
<div class="bg-green-50 p-4 rounded-lg text-center">
<div class="text-4xl font-bold text-green-600 mb-2" id="resultAccuracy">0%</div>
<div class="text-gray-600">Accuracy</div>
</div>
<div class="bg-purple-50 p-4 rounded-lg text-center">
<div class="text-4xl font-bold text-purple-600 mb-2" id="resultChars">0</div>
<div class="text-gray-600">Characters Typed</div>
</div>
</div>
<div class="mt-6 text-center">
<button id="shareBtn" class="px-6 py-2 bg-blue-100 text-blue-600 font-medium rounded-full hover:bg-blue-200 transition">
<i class="fas fa-share-alt mr-2"></i>Share Your Score
</button>
</div>
</div>
</div>
<script>
// Sample texts for typing test
const sampleTexts = [
"The quick brown fox jumps over the lazy dog. This sentence contains all the letters in the English alphabet. Typing is an essential skill in today's digital world.",
"Programming is the process of creating a set of instructions that tell a computer how to perform a task. It requires logical thinking and problem-solving skills.",
"The best way to predict the future is to invent it. Technology has transformed our lives in countless ways, making communication faster and more efficient.",
"Practice makes perfect. Regular typing practice can significantly improve your speed and accuracy over time. Consistency is key to mastering any skill.",
"The internet has revolutionized how we access information. With just a few keystrokes, we can find answers to almost any question imaginable."
];
// DOM elements
const typingText = document.getElementById('typingText');
const typingInput = document.getElementById('typingInput');
const timer = document.getElementById('timer');
const wpmDisplay = document.getElementById('wpm');
const progressBar = document.getElementById('progressBar');
const startBtn = document.getElementById('startBtn');
const retryBtn = document.getElementById('retryBtn');
const timeButtons = document.querySelectorAll('.time-btn');
const resultCard = document.getElementById('resultCard');
const resultWPM = document.getElementById('resultWPM');
const resultAccuracy = document.getElementById('resultAccuracy');
const resultChars = document.getElementById('resultChars');
const shareBtn = document.getElementById('shareBtn');
// Variables
let timeLeft = 0;
let timerInterval;
let totalTime = 0;
let isTyping = false;
let correctChars = 0;
let totalTyped = 0;
let currentText = '';
let currentIndex = 0;
let startTime;
let wpm = 0;
// Initialize
function init() {
typingInput.value = '';
typingInput.focus();
currentIndex = 0;
correctChars = 0;
totalTyped = 0;
wpm = 0;
updateWPM();
// Generate random text
currentText = sampleTexts[Math.floor(Math.random() * sampleTexts.length)];
// Display text with spans
typingText.innerHTML = '';
currentText.split('').forEach((char, index) => {
const span = document.createElement('span');
span.textContent = char;
span.id = `char-${index}`;
typingText.appendChild(span);
});
// Highlight first character
document.getElementById(`char-0`).classList.add('active');
}
// Start test
function startTest(seconds) {
if (isTyping) return;
totalTime = seconds;
timeLeft = seconds;
isTyping = true;
startTime = new Date().getTime();
init();
// Update timer display
updateTimer();
// Start timer
timerInterval = setInterval(() => {
timeLeft--;
updateTimer();
if (timeLeft <= 0) {
endTest();
}
}, 1000);
// UI changes
startBtn.classList.add('hidden');
retryBtn.classList.remove('hidden');
resultCard.classList.remove('show');
typingInput.focus();
}
// Update timer display
function updateTimer() {
const minutes = Math.floor(timeLeft / 60);
const seconds = timeLeft % 60;
timer.textContent = `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
// Update progress bar
const progressPercent = (timeLeft / totalTime) * 100;
progressBar.style.width = `${progressPercent}%`;
// Change color when time is running out
if (progressPercent < 30) {
progressBar.classList.remove('bg-blue-500');
progressBar.classList.add('bg-red-500');
} else {
progressBar.classList.remove('bg-red-500');
progressBar.classList.add('bg-blue-500');
}
}
// Update WPM display
function updateWPM() {
wpmDisplay.textContent = Math.round(wpm);
}
// Calculate WPM
function calculateWPM() {
if (!startTime) return 0;
const now = new Date().getTime();
const timeElapsed = (now - startTime) / 1000 / 60; // in minutes
const wordsTyped = correctChars / 5; // standard word length
return wordsTyped / timeElapsed || 0;
}
// Handle typing input
typingInput.addEventListener('input', (e) => {
if (!isTyping) return;
const inputChar = typingInput.value;
const currentChar = currentText[currentIndex];
// Remove active class from previous character
document.getElementById(`char-${currentIndex}`).classList.remove('active');
// Check if character is correct
if (inputChar === currentChar) {
document.getElementById(`char-${currentIndex}`).classList.add('correct');
correctChars++;
} else {
document.getElementById(`char-${currentIndex}`).classList.add('incorrect');
}
totalTyped++;
currentIndex++;
typingInput.value = '';
// Add active class to next character
if (currentIndex < currentText.length) {
document.getElementById(`char-${currentIndex}`).classList.add('active');
} else {
// If reached end of text, generate new text
currentText = sampleTexts[Math.floor(Math.random() * sampleTexts.length)];
typingText.innerHTML = '';
currentText.split('').forEach((char, index) => {
const span = document.createElement('span');
span.textContent = char;
span.id = `char-${index + currentIndex}`;
typingText.appendChild(span);
});
document.getElementById(`char-${currentIndex}`).classList.add('active');
}
// Calculate and update WPM
wpm = calculateWPM();
updateWPM();
});
// End test
function endTest() {
clearInterval(timerInterval);
isTyping = false;
// Calculate final results
const accuracy = Math.round((correctChars / totalTyped) * 100) || 0;
// Display results
resultWPM.textContent = Math.round(wpm);
resultAccuracy.textContent = `${accuracy}%`;
resultChars.textContent = totalTyped;
// Show result card
resultCard.classList.add('show');
// UI changes
typingInput.blur();
}
// Event listeners
startBtn.addEventListener('click', () => {
// Default to 60s if no time selected
const selectedTime = document.querySelector('.time-btn.active');
const time = selectedTime ? parseInt(selectedTime.id) : 60;
startTest(time);
});
retryBtn.addEventListener('click', () => {
const selectedTime = document.querySelector('.time-btn.active');
const time = selectedTime ? parseInt(selectedTime.id) : 60;
startTest(time);
});
timeButtons.forEach(button => {
button.addEventListener('click', () => {
timeButtons.forEach(btn => btn.classList.remove('bg-blue-600', 'text-white'));
button.classList.add('bg-blue-600', 'text-white');
});
});
shareBtn.addEventListener('click', () => {
if (navigator.share) {
navigator.share({
title: 'My Typing Test Results',
text: `I typed at ${resultWPM.textContent} WPM with ${resultAccuracy.textContent} accuracy! Can you beat my score?`,
url: window.location.href
}).catch(err => {
console.log('Error sharing:', err);
});
} else {
// Fallback for browsers that don't support Web Share API
const shareText = `I typed at ${resultWPM.textContent} WPM with ${resultAccuracy.textContent} accuracy! Try it yourself: ${window.location.href}`;
alert(shareText);
}
});
// Set default active time button
document.getElementById('60s').classList.add('bg-blue-600', 'text-white');
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=andreaschandra/type-racer" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html> |