forked from anushi13prsnl/Cyclotimer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.html
More file actions
166 lines (145 loc) · 6.66 KB
/
main.html
File metadata and controls
166 lines (145 loc) · 6.66 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Main Page</title>
<link rel="stylesheet" href="styles.css">
<link rel="icon" href="contents/images/clock.jpg">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css">
</head>
<body>
<header class="header">
<h2 class="logo"><a href="Logo-site.png" style="color: rgb(68, 5, 62);">CYCL<i
class="fa-solid fa-clock-rotate-left" style="font-size: 56px;"></i>TIMER</a></h2>
<ul class="main-nav">
<li><a href="index.html">Home</a></li>
<li><a href="about.html">About</a></li>
</ul>
</header>
<!-- this is edited by Abhinav-->
<div class="container2">
<div class="countdown-form">
<h2><strong>Set Countdown Timer</strong></h2>
<br>
<form id="countdownForm">
<div class="input-container2">
<label for="countdownInput" style="color: rgb(131, 172, 208);"><strong>Enter Time :
</strong></label>
<input type="number" id="countdownInput" required style="color: rgb(131, 172, 208);">
</div>
<div class="input-container3">
<label for="timeOptions2" style="color: rgb(131, 172, 208);"><strong>Include Time
:</strong> </label>
<div id="timeOptions2">
<input type="radio" id="secondsOption" name="time" style="color: rgb(131, 172, 208);" checked>
<label for="secondsOption">seconds </style></strong></label>
<input type="radio" id="minutesOption" name="time" style="color: rgb(131, 172, 208);">
<label for="minutesOption">minutes </strong><br></label><br>
</div>
</div>
<div class="input-container2">
<label for="timingOptions"
style="color:rgb(131, 172, 208);"><b>Pre-Defined Timings:</b> </strong></label>
<select id="timingOptions" style="color: rgb(129, 121, 121);" onchange="setPredefinedTime()">
<option value="0">Select time</option>
<option value="60">1 minute</option>
<option value="120">2 minutes</option>
<option value="300">5 minutes</option>
<option value="600">10 minutes</option>
</select>
</div>
<div class="btn-container">
<button type="button" onclick="startCountdown()">Start</button>
</div>
<div class="btn-container">
<button id="stopbutton" type="button" onclick="stopCountdown()">Stop</button>
<button id="resetbutton" type="button" onclick="resetCountdown()">Reset</button>
</div>
<div class="btn-container">
<h2><small>Countdown Timer</small></h2>
<div id="timer"></div>
</div>
</form>
</div>
</div>
<script>
var countdown;
var isStarted = false;
var startAudio = new Audio('contents/audio/audio.mp3');
var completionAudio = new Audio('contents/audio/audio2.mp3');
var remainingTime = 0;
function setPredefinedTime() {
var timingOptions = document.getElementById("timingOptions");
var selectedTiming = timingOptions.options[timingOptions.selectedIndex].value;
if (selectedTiming !== "0") {
if (document.getElementById("secondsOption").checked) {
document.getElementById("countdownInput").value = selectedTiming;
} else {
document.getElementById("countdownInput").value = selectedTiming / 60; // Convert to seconds
}
}
}
function startCountdown() {
if (isStarted) {
return;
}
var timerElement = document.getElementById("timer");
var timeOption = document.querySelector('input[name="time"]:checked').id;
startAudio.play();
var countdownInput = document.getElementById("countdownInput").value;
var time = parseInt(countdownInput);
if (isNaN(time) || time <= 0) {
timerElement.textContent = "Please enter a valid positive number";
return;
}
if (remainingTime > 0) {
time = remainingTime;
remainingTime = 0;
}
isStarted = true;
if (timeOption === "secondsOption") {
timerElement.textContent = time + " seconds remaining";
} else {
time *= 60;
timerElement.textContent = time + " seconds remaining";
}
countdown = setInterval(function () {
if (timeOption === "secondsOption") {
timerElement.textContent = time + " seconds remaining";
} else {
timerElement.textContent = time + " seconds remaining";
}
time--;
if (time < 0) {
clearInterval(countdown);
timerElement.textContent = "Time's up!";
startAudio.pause();
completionAudio.play();
}
remainingTime = time;
}, 1000);
}
function stopCountdown(){
if (isStarted) {
clearInterval(countdown);
isStarted = false;
startAudio.pause(); // If necessary to pause audio
var timerElement = document.getElementById("timer");
var timeString = timerElement.textContent;
var timeRemaining = parseInt(timeString.split(" ")[0]); // Extract remaining time
remainingTime = timeRemaining;
}}
function resetCountdown() {
clearInterval(countdown);
isStarted = false;
document.getElementById("timer").textContent = "";
document.getElementById("countdownInput").value = "";
document.getElementById("minutesOption").checked = false;
document.getElementById("secondsOption").checked = true;
document.getElementById("timingOptions").selectedIndex = 0;
startAudio.pause();
remainingTime = 0;
}
</script>
</body>
</html>