Files
ConnectHub/js/login.js
2024-09-25 20:49:15 +02:00

29 lines
1.1 KiB
JavaScript

document.addEventListener('DOMContentLoaded', () => {
const themeToggleBtn = document.getElementById('theme-toggle-btn');
const body = document.body;
// Ellenőrizzük, hogy van-e tárolt beállítás a localStorage-ban
const savedTheme = localStorage.getItem('theme');
// Alkalmazzuk a tárolt beállítást, ha van
if (savedTheme) {
body.classList.add(savedTheme === 'dark' ? 'dark-mode' : 'light-mode');
themeToggleBtn.textContent = savedTheme === 'dark' ? '☀️' : '🌙';
}
// Funkció a téma váltásához
themeToggleBtn.addEventListener('click', () => {
if (body.classList.contains('dark-mode')) {
body.classList.remove('dark-mode');
body.classList.add('light-mode');
themeToggleBtn.textContent = '🌙';
localStorage.setItem('theme', 'light'); // Mentés a localStorage-ba
} else {
body.classList.remove('light-mode');
body.classList.add('dark-mode');
themeToggleBtn.textContent = '☀️';
localStorage.setItem('theme', 'dark'); // Mentés a localStorage-ba
}
});
});