-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_20240130.ts
49 lines (39 loc) · 1.09 KB
/
main_20240130.ts
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
// 2024.01.30
interface Link {
title: string;
url: string;
comment: string;
}
const fetchData = () => {
const dataUrl = "links_20240117.json";
const xhr = new XMLHttpRequest();
xhr.open("GET", dataUrl, true);
xhr.responseType = "json";
xhr.onload = function () {
if (xhr.status === 200) {
const linksData: Link[] = xhr.response;
renderLinks(linksData);
} else {
console.error("Error fetching links.json. Status:", xhr.status);
}
};
xhr.send();
};
document.addEventListener("DOMContentLoaded", () => {
fetchData();
});
const renderLinks = (linksData: Link[]) => {
const linksContainer = document.getElementById("linksContainer");
if (linksContainer) {
linksData.forEach((link) => {
const linkItem = document.createElement("div");
linkItem.classList.add("link-item");
const linkAnchor = document.createElement("a");
linkAnchor.href = link.url;
linkAnchor.textContent = link.title;
linkAnchor.target = "_blank";
linkItem.appendChild(linkAnchor);
linksContainer.appendChild(linkItem);
});
}
};