| |
|
|
| document.addEventListener('DOMContentLoaded', () => { |
| const clickButton = document.getElementById('clickButton'); |
| const cpsDisplay = document.getElementById('cpsDisplay'); |
| const timerElement = document.getElementById('timer'); |
|
|
| let clickCount = 0; |
| let intervalId; |
| let testDuration = 15; |
|
|
| function startTest() { |
| |
| clickCount = 0; |
| cpsDisplay.textContent = 'CPS: 0.00'; |
| timerElement.textContent = testDuration; |
|
|
| |
| if (intervalId) { |
| clearInterval(intervalId); |
| } |
|
|
| |
| intervalId = setInterval(updateTimer, 1000); |
|
|
| |
| clickButton.classList.add('white'); |
| clickButton.textContent = clickCount; |
|
|
| |
| clickButton.removeEventListener('click', startTest); |
| clickButton.addEventListener('click', recordClick); |
| } |
|
|
| function updateTimer() { |
| testDuration--; |
| timerElement.textContent = testDuration; |
|
|
| if (testDuration <= 0) { |
| |
| clearInterval(intervalId); |
| clickButton.classList.remove('white'); |
| clickButton.textContent = 'Start'; |
| clickButton.addEventListener('click', startTest); |
|
|
| |
| displayFinalCPS(); |
|
|
| |
| testDuration = 15; |
| } |
| } |
|
|
| function recordClick() { |
| clickCount++; |
| clickButton.textContent = clickCount; |
| updateCPS(); |
| } |
|
|
| function updateCPS() { |
| const cps = clickCount / (15 - testDuration); |
| cpsDisplay.textContent = `CPS: ${cps.toFixed(2)}`; |
| } |
|
|
| function displayFinalCPS() { |
| const finalCPS = clickCount / 15; |
| cpsDisplay.textContent = `Final CPS: ${finalCPS.toFixed(2)}`; |
| } |
|
|
| |
| clickButton.addEventListener('click', startTest); |
| }); |
|
|