cps / script.js
Sergidev's picture
Update script.js
ee1b5be verified
raw
history blame
1.68 kB
// script.js
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; // Duration in seconds
function startTest() {
clickCount = 0;
cpsDisplay.textContent = 'CPS: 0.00';
timerElement.textContent = testDuration;
clickButton.classList.add('white');
clickButton.textContent = clickCount;
intervalId = setInterval(updateTimer, 1000);
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 = 'Done';
clickButton.removeEventListener('click', recordClick);
displayFinalCPS();
}
}
function recordClick() {
clickCount++;
clickButton.textContent = clickCount; // Update button with the new click count
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);
});