Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const textInput = document.getElementById('textInput');
+ const startButton = document.getElementById('startButton');
+ const readingContainer = document.getElementById('readingContainer');
+ const wordContainer = document.getElementById('wordContainer');
+ const inputSection = document.querySelector('.input-section');
+
+ let words = [];
+ let currentWordIndex = 0;
+
+ startButton.addEventListener('click', () => {
+ const text = textInput.value.trim();
+ if (text) {
+ words = text.split(/\s+/);
+ inputSection.classList.add('hidden');
+ readingContainer.classList.remove('hidden');
+ initializeReading();
+ }
+ });
+
+ function initializeReading() {
+ wordContainer.innerHTML = '';
+ words.forEach((word, index) => {
+ const wordSpan = document.createElement('span');
+ wordSpan.textContent = word;
+ wordSpan.classList.add('word');
+ wordSpan.dataset.index = index;
+ wordContainer.appendChild(wordSpan);
+
+ if (index < words.length - 1) {
+ wordContainer.appendChild(document.createTextNode(' '));
+ }
+ });
+
+ updateVisibility();
+ }
+
+ function updateVisibility() {
+ const scrollPercentage = window.scrollY / (document.documentElement.scrollHeight - window.innerHeight);
+ const wordIndex = Math.floor(scrollPercentage * words.length);
+
+ document.querySelectorAll('.word').forEach((wordSpan) => {
+ const index = parseInt(wordSpan.dataset.index);
+ if (index <= wordIndex) {
+ wordSpan.classList.add('visible');
+ } else {
+ wordSpan.classList.remove('visible');
+ }
+ });
+ }
+
+ window.addEventListener('scroll', () => {
+ if (!readingContainer.classList.contains('hidden')) {
+ updateVisibility();
+ }
+ });
+
+ window.addEventListener('resize', () => {
+ if (!readingContainer.classList.contains('hidden')) {
+ updateVisibility();
+ }
+ });
+ });