-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
73 lines (64 loc) · 1.92 KB
/
script.js
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
67
68
69
70
71
72
73
let root = document.documentElement
let rootStyle = getComputedStyle(root);
const urlParams = new URLSearchParams(window.location.search);
const pages = ["home", "socials", "aboutme", "stuffimade"];
function show(shown) {
for(let i = 0; i < pages.length; i++) {
document.getElementById(pages[i]).style.display = "none";
}
document.getElementById(shown).style.display = "block";
};
function showpage(page){
if(page) {
show(page);
window.history.replaceState(null, null, "?page=" + page);
} else {
if(urlParams.get('page')) {
show(urlParams.get('page'))
} else {
show("home");
}
}
}
function switchtheme() {
const currentTheme = rootStyle.getPropertyValue("--theme")
if (currentTheme == "dark") {
setProp("theme", "light")
document.cookie ="theme=light; expires=2147483647;"
setProp("background-1", "#f7fff7");
setProp("background-2", "#fffaf3");
setProp("foreground", "#575279");
setProp("button", "#eb6f92");
setProp("secondary", "#eb6f92");
for (var i of document.getElementsByClassName("svg")) {
i.setAttribute("fill", "#1c1a1e");
}
}
else if (currentTheme == "light") {
setProp("theme", "dark");
document.cookie ="theme=dark; expires=2147483647;"
setProp("background-1", "#191724");
setProp("background-2", "#1f1d2e");
setProp("foreground", "#e0def4");
setProp("button", "#31748f");
setProp("secondary", "#eb6f92");
for (var i of document.getElementsByClassName("svg")) {
i.setAttribute("fill", "#e0def4")
}
}
}
function setProp(name, value) {
root.style.setProperty('--' + name, value);
}
window.onload = function() {
if (getCookie("theme") == "light") {
switchtheme();
}
document.getElementById("age").innerHTML = ((Date.now() - 1180879200000)/ 1000 / 60 / 60 / 24 / 365.25 ).toFixed(4);
showpage()
}
function getCookie(name) {
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);
if (parts.length === 2) return parts.pop().split(';').shift();
}