mirror of
https://ghproxy.net/https://github.com/AlxMedia/shapebox.git
synced 2025-08-26 16:35:56 +08:00
22 lines
No EOL
680 B
JavaScript
22 lines
No EOL
680 B
JavaScript
// Get current theme
|
|
var theme = localStorage.getItem( 'theme' );
|
|
// Set defaults if theme is not defined.
|
|
if ( ! theme ) {
|
|
localStorage.setItem( 'theme', 'light' );
|
|
theme = 'light';
|
|
}
|
|
// Add theme to the body.
|
|
document.body.classList.add( theme );
|
|
|
|
// Handle onClick events
|
|
document.getElementById( 'theme-toggle' ).addEventListener( 'click', () => {
|
|
// Cleanup classes from body.
|
|
document.body.classList.remove( 'light' );
|
|
document.body.classList.remove( 'dark' );
|
|
// Change the theme.
|
|
theme = ( theme === 'light' ) ? 'dark' : 'light';
|
|
// Save the theme.
|
|
localStorage.setItem( 'theme', theme );
|
|
// Apply the theme.
|
|
document.body.classList.add( theme );
|
|
}); |