-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.html
More file actions
104 lines (89 loc) · 2.7 KB
/
timer.html
File metadata and controls
104 lines (89 loc) · 2.7 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Egg Timer</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="container timer-container">
<h1>Egg Timer</h1>
<div class="timer-main">
<div id="timer" class="timer-display">00:00</div>
<img id="egg-image" class="timer-egg-image" src="" alt="Egg" />
</div>
<div class="timer-controls">
<button id="start">Start</button>
<button id="pause">Pause</button>
<button id="reset">Reset</button>
</div>
</div>
<audio id="alarm" src="https://actions.google.com/sounds/v1/alarms/alarm_clock.ogg"></audio>
<script>
const params = new URLSearchParams(window.location.search);
const eggType = params.get('type')?.toLowerCase();
const eggTimes = {
soft: 5 * 60,
medium: 8 * 60,
hard: 11 * 60,
poach: 4 * 60,
sunny: 3 * 60,
omelette: 4 * 60,
};
const eggImages = {
soft: 'images/soft.jpg',
medium: 'images/medium.jpg',
hard: 'images/hard.jpg',
poach: 'images/poach.jpg',
sunny: 'images/sunny.jpg',
omelette: 'images/omelete.jpg',
};
const timerDisplay = document.getElementById('timer');
const eggImage = document.getElementById('egg-image');
const alarm = document.getElementById('alarm');
let duration = eggTimes[eggType] || 0;
let timeLeft = duration;
let timer = null;
if (!eggType || !eggTimes[eggType]) {
alert("Invalid egg type selected.");
window.location.href = "index.html";
}
eggImage.src = eggImages[eggType];
eggImage.alt = eggType.charAt(0).toUpperCase() + eggType.slice(1) + " egg";
function updateDisplay() {
const mins = Math.floor(timeLeft / 60).toString().padStart(2, '0');
const secs = (timeLeft % 60).toString().padStart(2, '0');
timerDisplay.textContent = `${mins}:${secs}`;
}
updateDisplay();
document.getElementById('start').onclick = () => {
if (!timer && timeLeft > 0) {
timer = setInterval(() => {
if (timeLeft > 0) {
timeLeft--;
updateDisplay();
} else {
clearInterval(timer);
timer = null;
alarm.play();
alert("Time's up! Your egg is ready.");
}
}, 1000);
}
};
document.getElementById('pause').onclick = () => {
if (timer) {
clearInterval(timer);
timer = null;
}
};
document.getElementById('reset').onclick = () => {
clearInterval(timer);
timer = null;
timeLeft = duration;
updateDisplay();
};
</script>
</body>
</html>