Debug: Add console logging to diagnose theme toggle issue

- Added detailed console logs to track theme toggle initialization
- Logs will help identify why button doesn't work on non-fg_scan pages
- Temporary debug code to be removed after fix
This commit is contained in:
Quality App System
2026-01-19 21:42:45 +02:00
parent 5837b74682
commit 68916a6f89

View File

@@ -25,6 +25,8 @@ const safeStorage = {
}; };
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
console.log('🔧 script.js DOMContentLoaded fired');
const reportButtons = document.querySelectorAll('.report-btn'); const reportButtons = document.querySelectorAll('.report-btn');
const reportTitle = document.getElementById('report-title'); const reportTitle = document.getElementById('report-title');
const reportTable = document.getElementById('report-table'); const reportTable = document.getElementById('report-table');
@@ -33,6 +35,8 @@ document.addEventListener('DOMContentLoaded', () => {
const themeToggleButton = document.getElementById('theme-toggle'); const themeToggleButton = document.getElementById('theme-toggle');
const body = document.body; const body = document.body;
console.log('🎨 Theme toggle button found:', themeToggleButton ? 'YES' : 'NO');
// Helper function to update the theme toggle button text // Helper function to update the theme toggle button text
function updateThemeToggleButtonText() { function updateThemeToggleButtonText() {
if (themeToggleButton) { if (themeToggleButton) {
@@ -46,6 +50,7 @@ document.addEventListener('DOMContentLoaded', () => {
// Check and apply the saved theme from localStorage // Check and apply the saved theme from localStorage
const savedTheme = safeStorage.getItem('theme'); const savedTheme = safeStorage.getItem('theme');
console.log('💾 Saved theme from localStorage:', savedTheme);
if (savedTheme) { if (savedTheme) {
body.classList.toggle('dark-mode', savedTheme === 'dark'); body.classList.toggle('dark-mode', savedTheme === 'dark');
} }
@@ -55,11 +60,16 @@ document.addEventListener('DOMContentLoaded', () => {
// Toggle the theme on button click // Toggle the theme on button click
if (themeToggleButton) { if (themeToggleButton) {
console.log('✅ Adding click listener to theme toggle button');
themeToggleButton.addEventListener('click', () => { themeToggleButton.addEventListener('click', () => {
console.log('🖱️ Theme toggle button clicked!');
const isDarkMode = body.classList.toggle('dark-mode'); const isDarkMode = body.classList.toggle('dark-mode');
safeStorage.setItem('theme', isDarkMode ? 'dark' : 'light'); safeStorage.setItem('theme', isDarkMode ? 'dark' : 'light');
console.log('🎨 Theme changed to:', isDarkMode ? 'dark' : 'light');
updateThemeToggleButtonText(); // Update the button text after toggling updateThemeToggleButtonText(); // Update the button text after toggling
}); });
} else {
console.warn('⚠️ Theme toggle button not found - event listener not added');
} }
// Date formatting is now handled consistently on the backend // Date formatting is now handled consistently on the backend