-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
146 lines (131 loc) · 4.55 KB
/
main.js
File metadata and controls
146 lines (131 loc) · 4.55 KB
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
const container = document.querySelector('.container');
const timeLeft = document.querySelector('.time-left');
const tapArea = document.querySelector('.tap-area');
const start = document.querySelector('.start');
const taps = document.querySelector('.taps');
const tapsPerSecond = document.querySelector('.taps-per-second');
const timeFive = document.querySelector('.time-5');
const timeFiveSpan = document.querySelector('.time-5 span');
const timeTen = document.querySelector('.time-10');
const timeTenSpan = document.querySelector('.time-10 span');
const timeFifteen = document.querySelector('.time-15');
const timeFifteenSpan = document.querySelector('.time-15 span');
let tapsValue = 0;
let timeValue = 5000;
let time = 0;
let flagFive = true;
let flagTen = true;
let flagFifteen = true;
const timeFiveFunc = () => {
timeValue = 5000;
timeLeft.textContent = "5.00";
flagFifteen = false;
flagTen = false;
if (flagFive === false) {
flagFive = true;
timeFifteen.classList.remove('timeBgcChange');
timeFifteenSpan.classList.remove('timeSpanColorChange');
timeTen.classList.remove('timeBgcChange');
timeTenSpan.classList.remove('timeSpanColorChange');
}
if (flagFive) {
timeFive.classList.add('timeBgcChange');
timeFiveSpan.classList.add('timeSpanColorChange');
}
}
timeFiveFunc();
timeFive.addEventListener('click', timeFiveFunc);
const timeTenFunc = () => {
timeValue = 10000;
timeLeft.textContent = "10.00";
flagFifteen = false;
flagFive = false;
if (flagTen === false) {
flagTen = true;
timeFifteen.classList.remove('timeBgcChange');
timeFifteenSpan.classList.remove('timeSpanColorChange');
timeFive.classList.remove('timeBgcChange');
timeFiveSpan.classList.remove('timeSpanColorChange');
}
if (flagTen) {
timeTen.classList.add('timeBgcChange');
timeTenSpan.classList.add('timeSpanColorChange');
}
}
timeTen.addEventListener('click', timeTenFunc)
const timeFifteenFunc = () => {
timeValue = 15000;
timeLeft.textContent = "15.00";
flagFive = false;
flagTen = false;
if (flagFifteen === false) {
flagFifteen = true;
timeFive.classList.remove('timeBgcChange');
timeFiveSpan.classList.remove('timeSpanColorChange');
timeTen.classList.remove('timeBgcChange');
timeTenSpan.classList.remove('timeSpanColorChange');
}
if (flagFifteen) {
timeFifteen.classList.add('timeBgcChange');
timeFifteenSpan.classList.add('timeSpanColorChange');
}
}
timeFifteen.addEventListener('click', timeFifteenFunc);
const startTapping = (e) => {
let x = e.clientX - e.target.offsetLeft;
let y = e.clientY - e.target.offsetTop;
let ripples = document.createElement('span');
ripples.className = 'animation';
ripples.style.left = x + "px";
ripples.style.top = y + "px";
tapArea.appendChild(ripples);
setTimeout(() => {
ripples.remove();
}, 500);
tapsValue++;
taps.textContent = `clicks: ${tapsValue}`;
}
const render = () => {
start.classList.add('hide');
tapArea.classList.add('show');
setTimeout(() => {
let perSecond = tapsValue / (timeValue / 1000);
tapsPerSecond.textContent = `clicks per second: ${perSecond.toFixed(2)}`;
setTimeout(() => {
start.classList.remove('hide');
tapArea.classList.remove('show');
}, 2000);
}, timeValue);
}
const countDown = () => {
const idInterval = setInterval(() => {
time++
timeLeft.textContent = (time / 100).toFixed(2);
timeFive.removeEventListener('click', timeFiveFunc);
timeTen.removeEventListener('click', timeTenFunc);
timeFifteen.removeEventListener('click', timeFifteenFunc);
if ((time * 10) === timeValue) {
window.clearInterval(idInterval);
tapArea.removeEventListener("click", startTapping);
timeFive.addEventListener('click', timeFiveFunc);
timeTen.addEventListener('click', timeTenFunc)
timeFifteen.addEventListener('click', timeFifteenFunc);
}
}, 10);
}
const Start = () => {
taps.textContent = `clicks: 0`;
tapsPerSecond.textContent = ``;
tapsValue = 0;
time = 0;
render();
countDown();
tapArea.addEventListener("click", startTapping);
tapArea.addEventListener('mouseup', () => {
tapArea.classList.remove('change-size');
})
tapArea.addEventListener('mousedown', () => {
tapArea.classList.add('change-size');
})
}
start.addEventListener('click', Start);