2022-07-05 14:38:32 +00:00
|
|
|
function addStyleSheet(name, id) {
|
2022-09-16 23:07:51 +00:00
|
|
|
var path = '/res/css/' + name + '.css';
|
2022-07-05 14:38:32 +00:00
|
|
|
var old = document.getElementById(id);
|
|
|
|
if (old && (old.href != path)) {
|
|
|
|
old.href = path;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var otherTheme = {
|
|
|
|
'dark': 'light',
|
|
|
|
'light': 'dark',
|
|
|
|
};
|
|
|
|
|
|
|
|
var currentTheme = localStorage.getItem('theme');
|
|
|
|
|
|
|
|
if (!otherTheme.hasOwnProperty(currentTheme)) {
|
|
|
|
currentTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
|
|
|
}
|
|
|
|
|
|
|
|
addStyleSheet(currentTheme, 'theme');
|
|
|
|
|
|
|
|
function toggleTheme() {
|
|
|
|
currentTheme = otherTheme[currentTheme] || 'light';
|
|
|
|
localStorage.setItem('theme', currentTheme);
|
|
|
|
addStyleSheet(currentTheme, 'theme');
|
2022-09-04 00:25:49 +00:00
|
|
|
}
|