mirror of
https://github.com/MeiK2333/github-style.git
synced 2025-10-07 01:54:06 +00:00
Update
This commit is contained in:
@@ -1,26 +1,2 @@
|
||||
function switchTheme() {
|
||||
const currentStyle = currentTheme();
|
||||
|
||||
if (currentStyle == 'light') {
|
||||
setTheme('dark');
|
||||
}
|
||||
else {
|
||||
setTheme('light');
|
||||
}
|
||||
}
|
||||
|
||||
function setTheme(style) {
|
||||
console.log(`set theme ${style}`);
|
||||
document.documentElement.setAttribute('data-theme', style);
|
||||
localStorage.setItem('data-theme', style);
|
||||
}
|
||||
|
||||
function currentTheme() {
|
||||
const localStyle = localStorage.getItem('data-theme');
|
||||
const systemStyle = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
||||
return localStyle || systemStyle;
|
||||
}
|
||||
|
||||
(() => {
|
||||
setTheme(currentTheme());
|
||||
})();
|
Reference in New Issue
Block a user