-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
66 lines (62 loc) · 1.85 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<title>Events on this day</title>
<style>
table {
table-layout: fixed;
width: 100%;
}
th:first-child,
td:first-child {
white-space: nowrap;
width: 5%;
}
</style>
</head>
<body>
<h1>Events on this day</h1>
<b>Showing events for <span id="current-date"></span></b>
<hr>
<table>
<thead>
<tr>
<th>Year</th>
<th>Description</th>
</tr>
</thead>
<tbody id="events">
</tbody>
</table>
<script>
// Get the current month and day
const now = new Date();
const month = now.getMonth() + 1;
const day = now.getDate();
const monthName = now.toLocaleString('default', { month: 'long' });
const currentDate = `${monthName}-${day}`;
// Set the current date in the page
const currentDateSpan = document.getElementById("current-date");
currentDateSpan.textContent = currentDate;
// Make the API request
const url = `https://byabbe.se/on-this-day/${month}/${day}/events.json`;
fetch(url)
.then(response => response.json())
.then(data => {
// Loop through the events and add them to the table
const eventsTable = document.getElementById("events");
for (const event of data.events) {
const row = document.createElement("tr");
const yearCell = document.createElement("td");
const descriptionCell = document.createElement("td");
yearCell.textContent = event.year;
descriptionCell.textContent = event.description;
row.appendChild(yearCell);
row.appendChild(descriptionCell);
eventsTable.appendChild(row);
}
})
.catch(error => console.error(error));
</script>
</body>
</html>