fix theme.js ty lucidiot ;w;
This commit is contained in:
parent
7367fd828b
commit
82f2ae984e
1 changed files with 18 additions and 15 deletions
17
theme.js
17
theme.js
|
@ -1,17 +1,20 @@
|
|||
var DEFAULT_THEME = "peach";
|
||||
var THEMES = [DEFAULT_THEME, "moon", "sakura", "honey"];
|
||||
window.addEventListener('load', function() {
|
||||
var prefersDarkScheme = window.matchMedia !== undefined && window.matchMedia("(prefers-color-scheme: dark)").matches;
|
||||
var DEFAULT_THEME = prefersDarkScheme ? 'moon' : 'peach';
|
||||
var THEMES = ["moon", "peach", "sakura", "honey"];
|
||||
|
||||
function setTheme(theme) {
|
||||
function setTheme(theme) {
|
||||
if (THEMES.indexOf(theme) < 0) theme = DEFAULT_THEME;
|
||||
document.getElementById('switcher-id').href = '/themes/' + theme + '.css';
|
||||
localStorage.setItem('style', theme);
|
||||
}
|
||||
}
|
||||
|
||||
setTheme(localStorage.getItem('style'));
|
||||
setTheme(localStorage.getItem('style'));
|
||||
|
||||
const switches = document.getElementsByClassName('switch');
|
||||
for (const el of switches) {
|
||||
const switches = document.getElementsByClassName('switch');
|
||||
for (const el of switches) {
|
||||
el.addEventListener('click', () => {
|
||||
setTheme(el.dataset.theme);
|
||||
});
|
||||
};
|
||||
})
|
Loading…
Add table
Reference in a new issue