-
Notifications
You must be signed in to change notification settings - Fork 0
/
notion_timer.html
204 lines (190 loc) · 6.55 KB
/
notion_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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Countdown Timer with Online Sound Player</title>
<style>
body {
background-color: black;
color: white;
font-family: Arial, sans-serif;
text-align: center;
margin: 0 20px;
padding: 0;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100vh;
}
.button {
background-color: grey;
color: white;
border: 2px solid white;
border-radius: 5px;
padding: 10px 20px;
cursor: pointer;
transition: background-color 0.3s, color 0.3s;
}
.button:hover {
background-color: lightgrey;
color: black;
text-shadow: 1px 1px 2px black;
}
.timer {
font-size: 48px;
margin-top: 20px;
padding: 10px;
border: 2px solid white;
border-radius: 5px;
width: 200px;
display: inline-block;
}
.play, .end {
margin-top: 20px;
margin-left: 10px;
padding: 10px 20px;
border: 2px solid white;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s, color 0.3s;
}
.play:hover, .end:hover {
background-color: lightgrey;
color: black;
text-shadow: 1px 1px 2px black;
}
.disabled {
opacity: 0.5;
cursor: not-allowed;
}
</style>
</head>
<body onload="resetTimer()">
<div>
<!-- Buttons to add time to the timer -->
<button class="button" onclick="addTime(300)">5 min</button>
<button class="button" onclick="addTime(900)">15 min</button>
<button class="button" onclick="addTime(1800)">30 min</button>
<button class="button" onclick="addTime(3600)">60 min</button>
</div>
<!-- Display countdown timer -->
<div id="countdown" class="timer"></div>
<div>
<!-- Buttons to control timer -->
<button id="playBtn" class="play" onclick="toggleTimer()">Play</button>
<button id="endBtn" class="end" onclick="resetTimer()">End</button>
</div>
<!-- YouTube Player container -->
<div id="youtubePlayer" style="display: none;"></div>
<script>
var countdown;
var timeLeft;
var timerDisplay = document.getElementById('countdown');
var isPaused = true;
// Load YouTube API script
function loadYouTubeAPI() {
var tag = document.createElement('script');
tag.src = 'https://www.youtube.com/iframe_api';
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
}
// YouTube API callback function
function onYouTubeIframeAPIReady() {
// Create YouTube player
window.youtubePlayer = new YT.Player('youtubePlayer', {
height: '0',
width: '0',
videoId: 'MIaLCgu6K0I', // Replace with your video ID
events: {
'onReady': onPlayerReady
}
});
}
// Function to start playback when player is ready
function onPlayerReady(event) {
event.target.playVideo();
}
// Function to add time to the timer
function addTime(duration) {
timeLeft += duration;
displayTime();
}
// Function to toggle timer
function toggleTimer() {
if (timeLeft > 0) {
if (isPaused) {
startCountdown();
document.getElementById('playBtn').innerText = 'Pause';
} else {
stopCountdown();
document.getElementById('playBtn').innerText = 'Play';
}
isPaused = !isPaused;
}
}
// Function to start countdown
function startCountdown() {
countdown = setInterval(function() {
timeLeft--;
displayTime();
if (timeLeft <= 0) {
clearInterval(countdown);
playAlarm();
document.getElementById('playBtn').classList.add('disabled');
document.getElementById('playBtn').disabled = true;
document.getElementById('playBtn').innerText = 'Play';
}
}, 1000);
}
// Function to stop countdown
function stopCountdown() {
clearInterval(countdown);
}
// Function to reset timer
function resetTimer() {
stopCountdown();
timeLeft = 0;
displayTime();
document.getElementById('playBtn').classList.remove('disabled');
document.getElementById('playBtn').disabled = false;
document.getElementById('playBtn').innerText = 'Play';
isPaused = true;
}
// Function to display time
function displayTime() {
if (!isNaN(timeLeft)) {
var hours = Math.floor(timeLeft / 3600);
var minutes = Math.floor((timeLeft % 3600) / 60);
var seconds = timeLeft % 60;
timerDisplay.textContent = pad(hours) + ":" + pad(minutes) + ":" + pad(seconds);
} else {
timerDisplay.textContent = "00:00:00";
}
if (timeLeft <= 0) {
document.getElementById('playBtn').classList.add('disabled');
document.getElementById('playBtn').disabled = true;
} else {
document.getElementById('playBtn').classList.remove('disabled');
document.getElementById('playBtn').disabled = false;
}
}
// Function to pad numbers with leading zeros
function pad(num) {
return num < 10 ? '0' + num : num;
}
// Function to play alarm sound
function playAlarm() {
// Load YouTube API and trigger playback
if (!window.YT) {
loadYouTubeAPI();
} else {
if (window.youtubePlayer) {
window.youtubePlayer.playVideo();
}
}
}
</script>
</body>
</html>