-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
62 lines (49 loc) · 1.69 KB
/
script.js
File metadata and controls
62 lines (49 loc) · 1.69 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
function getIcon(icon) {
if (!icon) return "";
if (icon === "whatsapp") return "fa-brands fa-whatsapp";
if (icon === "instagram") return "fa-brands fa-instagram";
if (icon === "tiktok") return "fa-brands fa-tiktok";
if (icon === "shopee") return "fa-brands fa-shopify";
if (icon === "lynk") return "fa-solid fa-link";
if (icon === "github") return "fa-brands fa-github";
return "fa-solid fa-link";
}
fetch("data.json")
.then(res => {
if (!res.ok) {
throw new Error("HTTP error " + res.status);
}
return res.json();
})
.then(data => {
const siteName = document.getElementById("siteName");
const sectionsDiv = document.getElementById("sections");
if (!siteName || !sectionsDiv) {
throw new Error("ID siteName atau sections tidak ditemukan");
}
siteName.innerText = data.siteName;
sectionsDiv.innerHTML = "";
data.sections.forEach(section => {
const title = document.createElement("div");
title.className = "section-title";
title.innerText = section.title;
const box = document.createElement("div");
box.className = "link-box";
section.links.forEach(link => {
const a = document.createElement("a");
a.className = "link-item";
a.href = link.url;
a.target = "_blank";
const iconClass = getIcon(link.icon);
a.innerHTML = iconClass
? `<i class="${iconClass}"></i> ${link.text}`
: link.text;
box.appendChild(a);
});
sectionsDiv.appendChild(title);
sectionsDiv.appendChild(box);
});
})
.catch(err => {
console.error("ERROR SCRIPT:", err.message);
});