forked from ShoroukAziz/notion_widgets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
timer.html
165 lines (122 loc) · 3.02 KB
/
timer.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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body{
background-color: aliceblue;
}
.section {
background-color: aliceblue;
padding: 10px;
width: fit-content;
}
#display{
margin-bottom: 5px;
font-size: 30px;
font-family: monospace;
color: darkturquoise;
}
.section input {
font-size: 8px;
color: #2D2D32;
text-align: center;
border: 1px solid gray;
width: 30px;
padding: 5px 1px;
margin-right: 4px;
display: inline-block;
}
.buttons {
display: flex;
flex-direction: row;
}
.buttons button {
margin-right: 4px;
padding: 5px 10px;
background-color: #d8d8d8;
border: none;
color: white;
font-size: 15px;
cursor: pointer;
outline: none;
transition: 0.1s;
}
.buttons button:active {
box-shadow: 0 3px 3px -2px rgba(0,0,0,.2), 0 3px 4px 0 rgba(0,0,0,.14), 0 1px 8px 0 rgba(0,0,0,.12);
}
.buttons button:last-child {
margin-right: 0;
}
.buttons button:nth-child(3){
background-color: #8bc34a;
}
.buttons button:nth-child(4){
background-color: rgb(201, 89, 69);
}
</style>
</head>
<body>
<section class="section">
<div id="display">0:00</div>
<div class="buttons">
<input type="text" id="input" name="input" placeholder="minutes">
<input type="text" id="input2" name="input2" placeholder="seconds">
<button onclick="start()">▶</button>
<button onclick="cancel()">∎</button>
</div>
</section>
</body>
<script>
function beep() {
var snd = new Audio("bell.mp3");
snd.play();
}
var timer;
function start(){
var input = document.getElementById("input").value;
var input2 = document.getElementById("input2").value;
minute = parseInt(input)
seconds1 = parseInt(input2)
if( isNaN(seconds1)){
seconds1 = 0
}
if( isNaN(minute)){
minute = 0
}
seconds = minute*60+seconds1
if(seconds==0){
return;
}
var textSec = "00"
textSec = seconds1
var display = document.getElementById("display");
display.innerHTML = minute + ':' + textSec
var statSec = seconds1
timer = setInterval(function(){
seconds--;
if(statSec != 0)
statSec--
else
statSec = 59
if(statSec < 10)
textSec = '0' + statSec
else
textSec = statSec
display.innerHTML = Math.floor(seconds/60) + ':' + textSec
if(seconds == 0){
console.log('d')
beep();
clearInterval(timer)
}
}, 1000)
}
function cancel(){
clearInterval(timer)
display.innerHTML ='00:00'
seconds = minute * 60
}
</script>
</html>