-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
112 lines (96 loc) · 2.82 KB
/
index.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/**
* Downloads by Url, necessary to include name and filetype as second and third arguments.
* @param {string} url - The url to download from.
* @param {string} name - The name the download will be saved as.
*/
async function downloadByUrl(url, name) {
try {
const response = await fetch(url);
const blob = await response.blob();
const link = document.createElement("a");
link.href = URL.createObjectURL(blob);
link.download = name;
link.click();
link.remove();
} catch (err) {
console.log(err);
}
};
function downloadVimrc() {
downloadByUrl("https://raw.githubusercontent.com/jacktrusler/dotfiles/main/.vimrc", "vimrc_example");
}
/* ----------------------------
Toggling Dark and Light mode
---------------------------- */
const toggle = document.getElementById("theme-toggle");
const sun = document.getElementById("sun");
const moon = document.getElementById("moon");
const logo = document.getElementById("logo-div");
const storedTheme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
if (storedTheme) {
document.documentElement.setAttribute('data-theme', storedTheme);
}
const cT = document.documentElement.getAttribute("data-theme");
if (cT === "dark" && moon) { moon.setAttribute("class", "moon hidden"); }
if (cT === "light" && sun) { sun.setAttribute("class", "sun hidden"); }
if (toggle) {
toggle.onclick = function() {
const currentTheme = document.documentElement.getAttribute("data-theme");
let targetTheme = "light";
if (currentTheme === "light") {
targetTheme = "dark";
moon.setAttribute("class", "moon hidden")
sun.setAttribute("class", "sun");
} else {
sun.setAttribute("class", "sun hidden");
moon.setAttribute("class", "moon");
}
document.documentElement.setAttribute('data-theme', targetTheme);
localStorage.setItem('theme', targetTheme);
}
}
if (logo) {
logo.onclick = function() {
const currentTheme = document.documentElement.getAttribute("data-theme");
let targetTheme = "light";
if (currentTheme === "light") {
targetTheme = "dark";
}
document.documentElement.setAttribute('data-theme', targetTheme);
localStorage.setItem('theme', targetTheme);
}
}
// ----------------------------
// JQuery
// ----------------------------
const years = [
'2021',
'2022',
'2023',
]
const months = [
'january',
'february',
'march',
'april',
'may',
'june',
'july',
'august',
'september',
'october',
'november',
'december',
]
for (const year of years) {
$(`#${year}-container`).hide();
$(`#${year}-year`).click(function() {
$(`#${year}-container`).toggle(500);
})
for (const month of months) {
$(`#${month}-${year}-container`).hide();
$(`#${month}-${year}`).click(function() {
$(`#${month}-${year}-container`).toggle(300);
})
}
}