-
Notifications
You must be signed in to change notification settings - Fork 0
/
hourglass.html
120 lines (100 loc) · 3.63 KB
/
hourglass.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
<head>
<title>Countdown Timer</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
background-color: #f0f0f0;
}
#tasktimer {
font-size: 48px;
margin: 4x;
}
button {
padding: 10px 20px;
font-size: 16px;
margin: 10px;
}
</style>
</head>
<body>
<h1 id="title">HourGlass Alpha ⏳😎</h1>
<p>Minutes: <input type="number" id="minutesInput" placeholder="Enter minutes" min="1">
</p>
<p>Tasks: <input type="number" id="tasksInput" placeholder="Enter tasks" min="0">
</p>
<!--<div id="taskInputs">
<input type="text" class="task-input1" placeholder="Enter task #1">
<input type="text" class="task-input2" placeholder="Enter task #2">
<input type="text" class="task-input3" placeholder="Enter task #3">
</div>
-->
<p>
<button onclick="addTask()">Add Task</button>
<button onclick="completeTask()">Complete Task</button>
</p>
<p></p>
Actual time remaining:
<div id="timer">00:00</div>
</p>
<p>
Time for each task:<div id="tasktimer">00:00</div></p>
<button id="start" onclick="toggleTimer()">Start</button>
<script>
let timerInterval;
let timeRemaining;
let isPaused = true;
let countTasks=3;
function toggleTimer() {
const minutesInput = document.getElementById('minutesInput').value;
if (isPaused) {
if (!timerInterval) {
timeRemaining = parseInt(minutesInput) * 60;
}
timerInterval = setInterval(updateTimer, 1000);
isPaused = false;
document.getElementById('start').textContent = 'Pause'
} else {
clearInterval(timerInterval);
timerInterval = null;
isPaused = true;
document.getElementById('start').textContent = 'Start'
}
}
function addTask() {
countTasks++;
document.getElementById('tasksInput').value = countTasks;
/*const newInput = document.createElement('input');
newInput.type = 'text';
newInput.className = 'task-input'+countTasks;
newInput.placeholder = 'Enter task #'+countTasks; */
}
function completeTask() {
countTasks-=1;
document.getElementById('tasksInput').value = countTasks;
}
function updateTimer() {
if (timeRemaining <= 0) {
clearInterval(timerInterval);
timerInterval = null;
document.getElementById('title').textContent = 'HourGlass Alpha ⏳😵'
return;
}
timeRemaining--;
const minutes = Math.floor(timeRemaining / 60);
const seconds = timeRemaining % 60;
taskTimeRemaining=Math.floor(timeRemaining/countTasks);
const taskminutes = Math.floor(taskTimeRemaining / 60);
const taskseconds = Math.floor(taskTimeRemaining % 60);
document.getElementById('timer').textContent =
`${minutes.toString()}:${seconds.toString().padStart(2, '0')}`;
document.getElementById('tasktimer').textContent =
`${taskminutes.toString()}:${taskseconds.toString().padStart(2, '0')}`;
}a
</script>
</body>
</html>