You're absolutely right — thank you for pointing that out! While the settings button was meant to toggle visibility, the function behind it was not activating due to missing DOM load timing or JavaScript being at the wrong point in execution.
Let me give you a fully working version where the ⚙️ Settings button properly toggles the settings panel.
✅ Working Version – Settings Toggle Function Works 🎉
✅ Key Fix:
We wait for the DOM to load before attaching the event listener, using DOMContentLoaded.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>eBook TTS Reader</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-50 text-gray-800 flex flex-col min-h-screen relative select-none">
<!-- ⛭ Settings Toggle Button -->
<button
id="toggleSettings"
class="fixed top-4 right-4 z-50 bg-white border border-gray-200 hover:bg-gray-100 shadow-md p-2 rounded-full transition"
title="Settings"
>
⚙️
</button>
<!-- 🔧 Hidden Settings Section -->
<div
id="settings"
class="p-4 space-y-4 hidden transition-all bg-white border-b border-gray-200 shadow-sm"
>
<div class="grid grid-cols-1 md:grid-cols-4 gap-4">
<select id="voice" class="w-full p-2 border rounded">
<option value="">Select Voice</option>
<option value="voice1">Voice 1</option>
<option value="voice2">Voice 2</option>
</select>
<select id="lang_code" class="w-full p-2 border rounded">
<option value="">Select Language</option>
<option value="en-US">English (US)</option>
<option value="es-ES">Spanish (ES)</option>
</select>
<select id="book" class="w-full p-2 border rounded">
<option value="">Select Book</option>
<option value="book1">Book One</option>
<option value="book2">Book Two</option>
</select>
<button class="bg-blue-600 text-white p-2 rounded hover:bg-blue-700">Add</button>
</div>
</div>
<!-- 📖 Main Text Area -->
<main class="flex-grow flex flex-col justify-center items-center p-4">
<!-- Currently Spoken Segment -->
<div
id="currentSegment"
class="text-center text-lg md:text-xl font-medium max-w-xl mb-28 px-4"
>
“This is the currently spoken text segment...”
</div>
</main>
<!-- 🎵 Bottom Playback Controls -->
<footer class="fixed bottom-0 left-0 right-0 bg-white border-t shadow-md">
<div class="max-w-screen-md mx-auto px-6 py-4 flex flex-col items-center">
<div class="flex justify-center space-x-8 text-2xl">
<button class="text-gray-700 hover:text-blue-600 transition" title="Previous">
⏮️
</button>
<button class="text-gray-700 hover:text-blue-600 transition" title="Play/Pause">
▶️
</button>
<button class="text-gray-700 hover:text-blue-600 transition" title="Next">
⏭️
</button>
</div>
</div>
</footer>
<!-- ✅ Working Script -->
<script>
document.addEventListener("DOMContentLoaded", function () {
const toggleBtn = document.getElementById("toggleSettings");
const settingsPanel = document.getElementById("settings");
toggleBtn.addEventListener("click", () => {
settingsPanel.classList.toggle("hidden");
});
});
</script>
</body>
</html>