Files

28 lines
704 B
JavaScript

const Theme = {
_current: 'dark',
_toggling: false,
init() {
this._current = localStorage.getItem('turbosu-theme') || 'dark';
this.apply();
},
toggle() {
if (this._toggling) return;
this._toggling = true;
this._current = this._current === 'dark' ? 'light' : 'dark';
this.apply();
setTimeout(() => { this._toggling = false; }, 200);
},
apply() {
document.body.classList.remove('theme-dark', 'theme-light');
document.body.classList.add(`theme-${this._current}`);
localStorage.setItem('turbosu-theme', this._current);
},
get current() { return this._current; }
};
window.Theme = Theme;