-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
35 lines (29 loc) · 896 Bytes
/
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
const themeChangeButton = document.getElementById('theme-change-button');
const mainImage = document.getElementById('main-img');
const script = [];
let themeCount;
let themeIndex = 1;
fetch('themes.json').then(r => r.json())
.then(data => {
for (const theme of data) {
script.push(theme);
}
themeCount = script.length;
});
function setStyleProperty(name, value) {
document.documentElement.style.setProperty(`--${name}`, value);
}
function applyTheme(theme) {
setStyleProperty('black', theme.black);
setStyleProperty('accent', theme.accent);
setStyleProperty('link', theme.link);
setStyleProperty('bg', theme.bg);
mainImage.src = theme.mainImg;
}
themeChangeButton.addEventListener('click', () => {
applyTheme(script[themeIndex]);
themeIndex++;
if (themeIndex === themeCount) {
themeIndex = 0;
}
});