-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
48 lines (42 loc) · 1.4 KB
/
Copy pathindex.js
File metadata and controls
48 lines (42 loc) · 1.4 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
async function setHTML(element, filePath) {
try {
const response = await fetch(filePath);
const htmlContent = await response.text();
element.innerHTML = htmlContent;
} catch (error) {
console.error('Error injecting HTML:', error);
}
}
async function injectHTML(event) {
const path = event?.target?.attributes.getNamedItem("href")?.value;
const contentDiv = document.getElementById("content");
console.debug(path);
setHTML(contentDiv, path);
}
async function switchTheme() {
const htmlVariables = document.documentElement;
currentTheme = htmlVariables.getAttribute("data-theme");
const switcherButton = document.getElementById("switcher");
htmlVariables.setAttribute("data-theme", currentTheme == "dark" ? "light" : "dark");
currentTheme = htmlVariables.getAttribute("data-theme");
console.debug("Setting theme ", currentTheme);
switch (currentTheme) {
case "dark":
switcherButton.setAttribute("src", "/assets/sun-svgrepo-com.png");
break;
case "light":
switcherButton.setAttribute("src", "/assets/moon-svgrepo-com.png");
break;
default:
console.warn("huh?");
break;
}
}
window.onload = (event) => {
console.log('Hello!\n');
const links = document.getElementsByClassName('section');
setHTML(document.getElementById("content"), "/home.html");
for (const link of links) {
link.addEventListener('click', injectHTML);
}
}