-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenderer.js
More file actions
49 lines (42 loc) · 1.3 KB
/
renderer.js
File metadata and controls
49 lines (42 loc) · 1.3 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
/* Este arquivo contém a lógica do cronômetro. */
let timer
let isRunning = false
let seconds = 0
const timerDisplay = document.getElementById('timer')
const startButton = document.getElementById('start')
const pauseButton = document.getElementById('pause')
const resetButton = document.getElementById('reset')
const closeButton = document.getElementById('close')
function updateDisplay() {
const hours = String(Math.floor(seconds / 3600)).padStart(2, '0')
const minutes = String(Math.floor((seconds % 3600) / 60)).padStart(2, '0')
const secs = String(seconds % 60).padStart(2, '0')
timerDisplay.textContent = `${hours}:${minutes}:${secs}`
}
startButton.addEventListener('click', () => {
if (!isRunning) {
isRunning = true
timer = setInterval(() => {
seconds++
updateDisplay()
}, 1000)
}
})
pauseButton.addEventListener('click', () => {
if (isRunning) {
clearInterval(timer)
isRunning = false
}
})
resetButton.addEventListener('click', () => {
clearInterval(timer)
seconds = 0
isRunning = false
updateDisplay()
})
closeButton.addEventListener('click', () => {
const confirmation = confirm("Você tem certeza que deseja fechar o aplicativo?")
if (confirmation) {
window.close()
}
})