diff --git a/scripts/videoplayer.js b/scripts/videoplayer.js index 09934f9..72b95c2 100644 --- a/scripts/videoplayer.js +++ b/scripts/videoplayer.js @@ -103,6 +103,24 @@ async function loadVideoSequenceByLetters() { currentIndex = 0; } +// Function to highlight the current word or letter +function highlightCurrentText(index) { + let wordsOrLetters = currentTranslationMode === 'words' ? inputText.value.trim().split(' ') : inputText.value.trim().split(''); + + // Reset the text content and remove previous highlights + inputText.innerHTML = ''; + + // Rebuild the text content with highlighting + wordsOrLetters.forEach((item, i) => { + const span = document.createElement('span'); + span.textContent = item + (currentTranslationMode === 'words' ? ' ' : ''); + if (i === index) { + span.classList.add('highlight'); + } + inputText.appendChild(span); + }); +} + // Function to play video at a specific index function playVideoAtIndex(index) { if (index < 0 || index >= videoSequence.length) return; @@ -111,6 +129,9 @@ function playVideoAtIndex(index) { videoPlayer.play(); currentIndex = index; + // Highlight the current word or letter + highlightCurrentText(currentIndex); + // Update the title with the current word or letter const currentLabel = videoSequence[index].split('/').pop().split('.')[0]; document.getElementById('currentLetter').innerText = currentLabel.toUpperCase();