-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfast.html
58 lines (50 loc) · 1.96 KB
/
fast.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fasting Tracker</title>
<style>
/* Add your CSS styles here for formatting */
</style>
</head>
<body>
<h1>Fasting Tracker</h1>
<label for="fast-start">Start fasting:</label>
<input type="datetime-local" id="fast-start">
<label for="fast-end">End fasting:</label>
<input type="datetime-local" id="fast-end">
<button onclick="addFastingRecord()">Add Record</button>
<h2>Records:</h2>
<ul id="records-list"></ul>
<script>
const recordsList = document.getElementById('records-list');
// Function to add a new fasting record
function addFastingRecord() {
const startTime = document.getElementById('fast-start').value;
const endTime = document.getElementById('fast-end').value;
if (!startTime || !endTime) {
alert("Please select both start and end times.");
return;
}
const fastingEntry = { start: startTime, end: endTime };
const fastingEntries = JSON.parse(localStorage.getItem('fastingEntries')) || [];
fastingEntries.push(fastingEntry);
localStorage.setItem('fastingEntries', JSON.stringify(fastingEntries));
updateRecordsList();
}
// Function to update the records list
function updateRecordsList() {
recordsList.innerHTML = '';
const fastingEntries = JSON.parse(localStorage.getItem('fastingEntries')) || [];
for (const entry of fastingEntries) {
const listItem = document.createElement('li');
listItem.textContent = `Started: ${entry.start}, Ended: ${entry.end}`;
recordsList.appendChild(listItem);
}
}
// Initialize the records list
updateRecordsList();
</script>
</body>
</html>