Compare commits

...

4 Commits

Author SHA1 Message Date
28468a596f funguje 2024-11-23 14:59:41 +00:00
d68e0f14c7 Update scripts/videoplayer.js 2024-11-23 14:16:39 +00:00
0a1286a905 Update styles/style.css 2024-11-23 14:13:07 +00:00
39bfe5dcfe #24 2024-11-23 14:12:28 +00:00
2 changed files with 34 additions and 2 deletions

View File

@ -53,7 +53,6 @@ async function fetchVideoUrl(word) {
return data.video_url; return data.video_url;
} }
// Function to load video sequence by words using Supabase // Function to load video sequence by words using Supabase
async function loadVideoSequenceByWords() { async function loadVideoSequenceByWords() {
const words = inputText.value.trim().split(' '); const words = inputText.value.trim().split(' ');
@ -104,6 +103,29 @@ async function loadVideoSequenceByLetters() {
currentIndex = 0; currentIndex = 0;
} }
// Function to highlight the current word or letter in the textarea
function highlightCurrentText(index) {
let wordsOrLetters = currentTranslationMode === 'words' ? inputText.value.trim().split(' ') : inputText.value.trim().split('');
// Reset the highlighted text in the textarea
inputText.value = '';
inputText.setSelectionRange(0, 0);
let startIndex = 0;
wordsOrLetters.forEach((item, i) => {
if (i < index) {
startIndex += item.length + (currentTranslationMode === 'words' ? 1 : 0);
}
});
let endIndex = startIndex + wordsOrLetters[index].length;
inputText.value = wordsOrLetters.join(currentTranslationMode === 'words' ? ' ' : '');
// Highlight the current word or letter
inputText.setSelectionRange(startIndex, endIndex);
inputText.focus();
}
// Function to play video at a specific index // Function to play video at a specific index
function playVideoAtIndex(index) { function playVideoAtIndex(index) {
if (index < 0 || index >= videoSequence.length) return; if (index < 0 || index >= videoSequence.length) return;
@ -112,6 +134,9 @@ function playVideoAtIndex(index) {
videoPlayer.play(); videoPlayer.play();
currentIndex = index; currentIndex = index;
// Highlight the current word or letter
highlightCurrentText(currentIndex);
// Update the title with the current word or letter // Update the title with the current word or letter
const currentLabel = videoSequence[index].split('/').pop().split('.')[0]; const currentLabel = videoSequence[index].split('/').pop().split('.')[0];
document.getElementById('currentLetter').innerText = currentLabel.toUpperCase(); document.getElementById('currentLetter').innerText = currentLabel.toUpperCase();
@ -194,4 +219,4 @@ inputText.addEventListener('input', () => {
} else { } else {
translateBtn.disabled = true; // Disable the translate button if the text is empty translateBtn.disabled = true; // Disable the translate button if the text is empty
} }
}); });

View File

@ -153,6 +153,13 @@ h1 {
background-color: #357ae8; background-color: #357ae8;
} }
/* Zvýraznenie pre aktuálne slovo/písmeno */
.highlight {
background-color: #ffeb3b; /* Svetložltá farba na zvýraznenie */
font-weight: bold;
color: #333;
}
.video { .video {
position: relative; position: relative;
width: 45%; width: 45%;