-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
150 lines (128 loc) · 3.68 KB
/
script.js
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
(function () {
const startButton = document.querySelector('.btn:nth-child(1)')
const stopButton = document.querySelector('.btn:nth-child(2)')
const copyButton = document.querySelector('.btn:nth-child(3)')
const spanHours = document.querySelector('#hours')
const spanMinutes = document.querySelector('#minutes')
const spanSeconds = document.querySelector('#seconds')
const spanMilliseconds = document.querySelector('#milliseconds')
let stopped = false
let milliseconds
let seconds
let minutes
let hours
let icon = document.createElement('i')
icon.classList = 'fa-stop fa'
let icon2 = document.createElement('i')
icon2.classList = 'fas fa-backward'
let interval
let state = false
let pressStart = false
let clearButton = false
function handleStartClick(){
pressStart = true
if(clearButton){
changeButtonToStop()
clearButton = false
}
if(!state){
state = true
if(!stopped){
milliseconds = 0
seconds = 0
minutes = 0
hours = 0
}
stopped = false
interval = setInterval((e) => {
milliseconds += 100
if(milliseconds == 1000){
spanMilliseconds.textContent = 00
}else{
spanMilliseconds.textContent = milliseconds
}
if(milliseconds == 1000){
seconds++
if(seconds < 10)
spanSeconds.textContent = '0' + seconds
else
spanSeconds.textContent = seconds
milliseconds = 000
}
if(seconds == 60){
spanSeconds.textContent = 00
}else{
spanSeconds.textContent = seconds
}
if(seconds == 60){
minutes++
spanMinutes.textContent = minutes
seconds = 0
}
if(minutes == 60){
hours++
spanHours.textContent = hours
minutes =0
}
}, 100);
}
}
function copyToClip() {
let node = document.querySelector('#numbers')
let text = document.createElement('textarea')
text.value = node.textContent.replace(/[^\w\d:]/g, '')
document.body.appendChild(text)
text.select()
node.focus()
document.execCommand('copy')
document.body.removeChild(text)
alert('Copied to clipboard ---->'+ node.textContent.replace(/[^\w\d:]/g, ''))
}
function handleStopClick() {
if(!pressStart)
return
if(state == false){
changeButtonToStop()
clearButton = false
spanMilliseconds.textContent = '000'
spanSeconds.textContent = '00'
spanMinutes.textContent = '00'
spanHours.textContent = '00'
milliseconds = '00'
seconds = '00'
minutes = '00'
hours = '00'
clearInterval(interval)
pressStart = false
state = false
stopped = false
return
}
changeButtonToClear()
clearButton = true
state = false
clearInterval(interval)
stopped = true;
}
function changeButtonToStop(){
let p = document.createElement('p')
stopButton.classList.toggle('stop')
p.textContent = 'STOP'
stopButton.textContent = ''
stopButton.classList.toggle('clear')
stopButton.appendChild(p)
stopButton.insertBefore(icon, p)
}
function changeButtonToClear(){
stopButton.textContent = ''
stopButton.classList.toggle('clear')
stopButton.classList.toggle('stop')
let p2 = document.createElement('p')
p2.textContent = 'CLEAR'
stopButton.appendChild(p2)
stopButton.insertBefore(icon2, p2)
}
startButton.addEventListener('click', handleStartClick ,false)
stopButton.addEventListener('click', handleStopClick, false)
copyButton.addEventListener('click',copyToClip,false )
})()