-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (25 loc) · 1.16 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
function setColorTheme(value) {
const root = document.documentElement;
const themes = [`--dark`, '--gray', '--light'];
root.style.setProperty('--bg-color', `var(${themes[value]}-bg-color)`)
root.style.setProperty('--text-color', `var(${themes[value]}-text-color)`)
root.style.setProperty('--accent-color', `var(${themes[value]}-accent-color)`)
}
function setSizeTheme(value) {
const root = document.documentElement;
const themes = [`--small`, '--medium', '--large'];
root.style.setProperty('--font-size', `var(${themes[value]}-font-size)`)
}
document.addEventListener('DOMContentLoaded', function documentListener() {
const themeToggler = document.getElementById('colorTheme');
const sizeToggler = document.getElementById('sizeTheme');
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches) {
themeToggler.value = 2;
}
themeToggler.addEventListener('input', function setColorThemeListener({ target: { value } }) {
setColorTheme(value)
})
sizeToggler.addEventListener('input', function setSizeThemeListener({ target: { value } }) {
setSizeTheme(value)
})
})