-
Notifications
You must be signed in to change notification settings - Fork 0
/
cronometro.html
93 lines (82 loc) · 1.75 KB
/
cronometro.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="author" content="charlybs">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title id="title">00:00:00</title>
<style>
* {
text-align: center;
font-size: 50px;
font-weight: bold;
font-family: arial;
color:white;
background-color: #1C1C1C;
}
</style>
</head>
<body>
<p>Cronómetro</p>
<p id="cron">00:00:00</p>
<button onclick="start()">Start</button>
<button id="pause" onclick="pause()">Pause</button>
<button onclick="reset()">Reset</button>
<script>
var hour = 0;
var minute = 0;
var second = 0;
var cron;
function start() {
if(cron !== undefined){
return;
}
cron = setInterval(function(){
second += 1;
if(second==60)
{
minute += 1;
second = 0;
}
if(minute==60){
hour += 1;
minute = 0;
}
document.getElementById("title").innerHTML = printTime();
document.getElementById("cron").innerHTML = printTime();
}, 999)
}
function reset() {
hour = 0;
minute = 0;
second = 0;
document.getElementById("cron").innerHTML = printTime();
document.getElementById("title").innerHTML = printTime();
}
function pause() {
if(cron == undefined && second==0 && minute==0){
return;
}
let text = document.getElementById("pause").firstChild;
if(text.data=="Pause"){
text.data = "Resume";
clearInterval(cron);
}else{
text.data = "Pause";
resume();
}
}
function resume() {
cron = undefined;
start();
}
function printTime() {
let hour_, minute_, second_;
hour_ = hour < 10 ? "0" + hour : hour;
minute_ = minute < 10 ? "0" + minute : minute;
second_ = second < 10 ? "0" + second : second;
return hour_ + ":" + minute_ + ":" + second_;
}
</script>
</body>
</html>