mirror of
https://github.com/mivodev/plugin-mivo-theme.git
synced 2026-01-27 05:42:04 +07:00
25 lines
668 B
JavaScript
25 lines
668 B
JavaScript
function initTheme() {
|
|
return {
|
|
theme: localStorage.getItem('mivo_theme') || 'dark',
|
|
toggle() {
|
|
this.theme = this.theme === 'dark' ? 'light' : 'dark';
|
|
this.apply();
|
|
},
|
|
setTheme(val) {
|
|
this.theme = val;
|
|
this.apply();
|
|
},
|
|
apply() {
|
|
localStorage.setItem('mivo_theme', this.theme);
|
|
if (this.theme === 'dark') {
|
|
document.documentElement.classList.add('dark');
|
|
} else {
|
|
document.documentElement.classList.remove('dark');
|
|
}
|
|
},
|
|
init() {
|
|
this.apply();
|
|
}
|
|
}
|
|
}
|