mirror of
https://github.com/nextcloud/all-in-one.git
synced 2025-12-19 22:16:49 +00:00
26 lines
1.1 KiB
JavaScript
26 lines
1.1 KiB
JavaScript
|
|
// Function to toggle theme
|
||
|
|
function toggleTheme() {
|
||
|
|
const currentTheme = document.documentElement.getAttribute('data-theme');
|
||
|
|
const newTheme = (currentTheme === 'dark') ? 'light' : 'dark';
|
||
|
|
document.documentElement.setAttribute('data-theme', newTheme);
|
||
|
|
localStorage.setItem('theme', newTheme);
|
||
|
|
|
||
|
|
// Change the icon based on the current theme
|
||
|
|
const themeIcon = document.getElementById('theme-icon');
|
||
|
|
themeIcon.textContent = newTheme === 'dark' ? '☀️' : '🌙'; // Switch between moon and sun icons
|
||
|
|
}
|
||
|
|
|
||
|
|
// Function to apply saved theme from localStorage
|
||
|
|
function applySavedTheme() {
|
||
|
|
const savedTheme = localStorage.getItem('theme');
|
||
|
|
if (savedTheme) {
|
||
|
|
document.documentElement.setAttribute('data-theme', savedTheme);
|
||
|
|
|
||
|
|
// Ensure the icon is set correctly based on the saved theme
|
||
|
|
const themeIcon = document.getElementById('theme-icon');
|
||
|
|
themeIcon.textContent = savedTheme === 'dark' ? '☀️' : '🌙';
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// Apply theme when the page loads
|
||
|
|
document.addEventListener('DOMContentLoaded', applySavedTheme);
|