Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const generateButton = document.getElementById('generate-story');
+ const storyPrompt = document.getElementById('story-prompt');
+ const storyDisplay = document.querySelector('.story-display');
+ const playPauseButton = document.getElementById('play-pause');
+ const prevButton = document.getElementById('previous-page');
+ const nextButton = document.getElementById('next-page');
+
+ let currentPage = 0;
+ let isPlaying = false;
+ let speech = null;
+
+ const dummyStory = {
+ pages: [
+ {
+ text: "Once upon a time, in a magical forest...",
+ image: "🌳"
+ },
+ {
+ text: "There lived a wonderful creature who loved adventures...",
+ image: "🦄"
+ },
+ {
+ text: "And they lived happily ever after!",
+ image: "✨"
+ }
+ ]
+ };
+
+ generateButton.addEventListener('click', () => {
+ if (!storyPrompt.value.trim()) {
+ alert('Please enter a story prompt first!');
+ return;
+ }
+
+ storyDisplay.hidden = false;
+ currentPage = 0;
+ updateStoryDisplay();
+
+ // Smooth scroll to story
+ storyDisplay.scrollIntoView({ behavior: 'smooth' });
+ });
+
+ function updateStoryDisplay() {
+ const illustration = document.querySelector('.illustration');
+ const storyText = document.querySelector('.story-text');
+
+ illustration.textContent = dummyStory.pages[currentPage].image;
+ storyText.textContent = dummyStory.pages[currentPage].text;
+
+ prevButton.disabled = currentPage === 0;
+ nextButton.disabled = currentPage === dummyStory.pages.length - 1;
+ }
+
+ playPauseButton.addEventListener('click', () => {
+ if (isPlaying) {
+ stopNarration();
+ } else {
+ startNarration();
+ }
+ });
+
+ function startNarration() {
+ if ('speechSynthesis' in window) {
+ speech = new SpeechSynthesisUtterance(
+ document.querySelector('.story-text').textContent
+ );
+ speech.rate = 0.9;
+ speech.pitch = 1.1;
+ window.speechSynthesis.speak(speech);
+ isPlaying = true;
+ playPauseButton.querySelector('.icon').textContent = '⏸️';
+ }
+ }
+
+ function stopNarration() {
+ window.speechSynthesis.cancel();
+ isPlaying = false;
+ playPauseButton.querySelector('.icon').textContent = '▶️';
+ }
+
+ prevButton.addEventListener('click', () => {
+ if (currentPage > 0) {
+ currentPage--;
+ updateStoryDisplay();
+ stopNarration();
+ }
+ });
+
+ nextButton.addEventListener('click', () => {
+ if (currentPage < dummyStory.pages.length - 1) {
+ currentPage++;
+ updateStoryDisplay();
+ stopNarration();
+ }
+ });
+
+ // Age group selection
+ document.querySelectorAll('.age-group').forEach(button => {
+ button.addEventListener('click', () => {
+ document.querySelectorAll('.age-group').forEach(btn =>
+ btn.style.background = 'transparent'
+ );
+ button.style.background = 'white';
+ button.style.color = 'var(--primary-color)';
+ });
+ });
+ });