Update script.js
Browse files
script.js
CHANGED
@@ -1,40 +1,59 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
document.getElementById('
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
intervalId
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
}
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
clicks++;
|
31 |
-
document.getElementById('click-counter').innerHTML = clicks.toString();
|
32 |
-
cps = clicks / (new Date().getTime() - startTime) * 1000;
|
33 |
-
document.getElementById('cps-display').innerHTML = `Clicks Per Second: ${cps.toFixed(2)}`;
|
34 |
-
}
|
35 |
-
|
36 |
-
function endTest() {
|
37 |
-
clearInterval(intervalId);
|
38 |
-
document.getElementById('cps-display').innerHTML = `Total Clicks Per Second: ${cps.toFixed(2)}`;
|
39 |
-
document.removeEventListener('click', countClick);
|
40 |
-
}
|
|
|
1 |
+
// script.js
|
2 |
+
|
3 |
+
document.addEventListener('DOMContentLoaded', () => {
|
4 |
+
const clickButton = document.getElementById('clickButton');
|
5 |
+
const clickCounter = document.getElementById('clickCounter');
|
6 |
+
const cpsDisplay = document.getElementById('cpsDisplay');
|
7 |
+
const timerElement = document.getElementById('timer');
|
8 |
+
|
9 |
+
let clickCount = 0;
|
10 |
+
let intervalId;
|
11 |
+
let testDuration = 15; // Duration in seconds
|
12 |
+
|
13 |
+
function startTest() {
|
14 |
+
clickCount = 0;
|
15 |
+
clickCounter.textContent = clickCount;
|
16 |
+
cpsDisplay.textContent = 'CPS: 0.00';
|
17 |
+
timerElement.textContent = testDuration;
|
18 |
+
|
19 |
+
clickButton.classList.add('white');
|
20 |
+
clickButton.textContent = clickCount;
|
21 |
+
|
22 |
+
intervalId = setInterval(updateTimer, 1000);
|
23 |
+
|
24 |
+
clickButton.removeEventListener('click', startTest);
|
25 |
+
clickButton.addEventListener('click', recordClick);
|
26 |
+
}
|
27 |
+
|
28 |
+
function updateTimer() {
|
29 |
+
testDuration--;
|
30 |
+
timerElement.textContent = testDuration;
|
31 |
+
|
32 |
+
if (testDuration <= 0) {
|
33 |
+
clearInterval(intervalId);
|
34 |
+
clickButton.classList.remove('white');
|
35 |
+
clickButton.textContent = 'Done';
|
36 |
+
clickButton.removeEventListener('click', recordClick);
|
37 |
+
displayFinalCPS();
|
38 |
+
}
|
39 |
+
}
|
40 |
+
|
41 |
+
function recordClick() {
|
42 |
+
clickCount++;
|
43 |
+
clickCounter.textContent = clickCount;
|
44 |
+
clickButton.textContent = clickCount;
|
45 |
+
updateCPS();
|
46 |
+
}
|
47 |
+
|
48 |
+
function updateCPS() {
|
49 |
+
const cps = clickCount / (15 - testDuration);
|
50 |
+
cpsDisplay.textContent = `CPS: ${cps.toFixed(2)}`;
|
51 |
+
}
|
52 |
+
|
53 |
+
function displayFinalCPS() {
|
54 |
+
const finalCPS = clickCount / 15;
|
55 |
+
cpsDisplay.textContent = `Final CPS: ${finalCPS.toFixed(2)}`;
|
56 |
}
|
57 |
+
|
58 |
+
clickButton.addEventListener('click', startTest);
|
59 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|