-
Notifications
You must be signed in to change notification settings - Fork 0
/
theme.client.js
28 lines (21 loc) · 934 Bytes
/
theme.client.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
// November 2021, dxstiny (https://github.com/dxstiny)
// check out the README.md!
import themes from "./themes.json";
//fetch("/assets/themes/themes.json").then(x => x.json()).then(json => themes = json) // in case you can't use import
const LOCAL_STORAGE_KEY = "theme" // change it to whatever you like
window.getThemes = () => { // returns a string array of all available themes
window.themes = Object.keys(themes[Object.keys(themes)[0]]);
return window.themes;
}
window.setTheme = (theme) => { // accepts a string (theme name)
if (!window.getThemes().includes(theme))
{
return;
}
window.localStorage.setItem(LOCAL_STORAGE_KEY, theme)
for (const key of Object.keys(themes))
{
document.documentElement.style.setProperty(`--${key}`, themes[key][theme]);
}
}
window.setTheme(window.localStorage.getItem(LOCAL_STORAGE_KEY) || "dark-neon") // optional, loads the default theme