Add existing files
This commit is contained in:
parent
dc625dcbe5
commit
8cfb858b77
40 changed files with 1188 additions and 0 deletions
26
res/js/themeswap.js
Executable file
26
res/js/themeswap.js
Executable file
|
@ -0,0 +1,26 @@
|
|||
function addStyleSheet(name, id) {
|
||||
var path = '/res/css/' + name + '.min.css';
|
||||
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');
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue