mirror of
https://github.com/Rainyy21/Rainyy21.github.io.git
synced 2026-10-10 23:50:17 -04:00
22 lines
559 B
JavaScript
22 lines
559 B
JavaScript
let darkmode = localStorage.getItem('dark');
|
|
const switch_button = document.getElementById("theme_switch");
|
|
|
|
const enableDarkmode = () => {
|
|
document.body.classList.add('dark');
|
|
localStorage.setItem('dark' , 'active');
|
|
}
|
|
|
|
const disableDarkmode = () => {
|
|
document.body.classList.remove('dark');
|
|
localStorage.removeItem('dark');
|
|
};
|
|
|
|
if (darkmode === 'active') enableDarkmode();
|
|
|
|
switch_button.addEventListener("click", () => {
|
|
darkmode = localStorage.getItem('dark');
|
|
darkmode !== "active" ? enableDarkmode() : disableDarkmode();
|
|
});
|
|
|
|
|