fixed db implementacia
This commit is contained in:
parent
99b6bb8ecf
commit
d6d78a3fb8
@ -45,9 +45,9 @@
|
|||||||
|
|
||||||
|
|
||||||
<!-- Pripojenie skriptov -->
|
<!-- Pripojenie skriptov -->
|
||||||
|
<script type="module" src="videoplayer.js"></script>
|
||||||
<script src="kontrola_api.js"></script>
|
<script src="kontrola_api.js"></script>
|
||||||
<script src="speech_recognition.js"></script>
|
<script src="speech_recognition.js"></script>
|
||||||
<script src="videoplayer.js"></script>
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,3 +1,8 @@
|
|||||||
|
import { createClient } from 'https://cdn.jsdelivr.net/npm/@supabase/supabase-js/+esm';
|
||||||
|
const supabaseUrl = 'https://manesldshonpegglmyan.supabase.co'
|
||||||
|
const supabaseKey = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im1hbmVzbGRzaG9ucGVnZ2xteWFuIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTczMDcxNzQ2NCwiZXhwIjoyMDQ2MjkzNDY0fQ.saaJeTtwYZCS3YKJYmQsAOSAEFzUVUJnoJSD8-lgLHo'
|
||||||
|
const supabase = createClient(supabaseUrl, supabaseKey)
|
||||||
|
|
||||||
const inputText = document.getElementById('inputText');
|
const inputText = document.getElementById('inputText');
|
||||||
const videoPlayer = document.getElementById('translationVideo');
|
const videoPlayer = document.getElementById('translationVideo');
|
||||||
const translateWordsBtn = document.getElementById('translateWordsBtn');
|
const translateWordsBtn = document.getElementById('translateWordsBtn');
|
||||||
@ -5,14 +10,13 @@ const translateLettersBtn = document.getElementById('translateLettersBtn');
|
|||||||
const prevBtn = document.getElementById('prevBtn');
|
const prevBtn = document.getElementById('prevBtn');
|
||||||
const nextBtn = document.getElementById('nextBtn');
|
const nextBtn = document.getElementById('nextBtn');
|
||||||
const translateBtn = document.getElementById('translateBtn');
|
const translateBtn = document.getElementById('translateBtn');
|
||||||
|
const statusText = document.getElementById('statusText');
|
||||||
|
|
||||||
let videoSequence = [];
|
let videoSequence = [];
|
||||||
let currentIndex = 0;
|
let currentIndex = 0;
|
||||||
let autoPlayEnabled = true;
|
let autoPlayEnabled = true;
|
||||||
|
|
||||||
let currentTranslationMode = 'words';
|
let currentTranslationMode = 'words';
|
||||||
|
|
||||||
|
|
||||||
async function videoExists(src) {
|
async function videoExists(src) {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
const video = document.createElement('video');
|
const video = document.createElement('video');
|
||||||
@ -22,20 +26,53 @@ async function videoExists(src) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function fetchVideoUrl(word) {
|
||||||
|
const { data, error } = await supabase
|
||||||
|
.from('Videa')
|
||||||
|
.select('video_url')
|
||||||
|
.eq('label', word)
|
||||||
|
.maybeSingle();
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
console.error('Error fetching video:', error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return data.video_url;
|
||||||
|
}
|
||||||
|
|
||||||
async function loadVideoSequenceByWords() {
|
async function loadVideoSequenceByWords() {
|
||||||
const words = inputText.value.trim().split(' ');
|
const words = inputText.value.trim().split(' ');
|
||||||
videoSequence = [];
|
videoSequence = [];
|
||||||
|
|
||||||
for (const word of words) {
|
for (const word of words) {
|
||||||
const videoSrc = `video/${word.toLowerCase()}.mp4`;
|
const videoUrl = await fetchVideoUrl(word.toLowerCase());
|
||||||
if (await videoExists(videoSrc)) {
|
if (videoUrl) {
|
||||||
videoSequence.push(videoSrc);
|
videoSequence.push(videoUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
currentIndex = 0;
|
currentIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function fetchLetterVideoUrl(letter) {
|
||||||
|
const { data, error } = await supabase
|
||||||
|
.from('Videa')
|
||||||
|
.select('video_url')
|
||||||
|
.eq('label', letter)
|
||||||
|
.maybeSingle();
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
console.error('Error fetching video for letter:', letter, error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!data) {
|
||||||
|
console.warn(`No video found for letter: ${letter}`);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return data.video_url;
|
||||||
|
}
|
||||||
|
|
||||||
async function loadVideoSequenceByLetters() {
|
async function loadVideoSequenceByLetters() {
|
||||||
const characters = inputText.value.trim().split('');
|
const characters = inputText.value.trim().split('');
|
||||||
@ -43,16 +80,15 @@ async function loadVideoSequenceByLetters() {
|
|||||||
|
|
||||||
for (const char of characters) {
|
for (const char of characters) {
|
||||||
if (/[a-zA-Z]/.test(char)) {
|
if (/[a-zA-Z]/.test(char)) {
|
||||||
const videoSrc = `video/pismena/${char.toLowerCase()}.mp4`;
|
const videoUrl = await fetchLetterVideoUrl(char.toLowerCase());
|
||||||
if (await videoExists(videoSrc)) {
|
if (videoUrl) {
|
||||||
videoSequence.push(videoSrc);
|
videoSequence.push(videoUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
currentIndex = 0;
|
currentIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function playVideoAtIndex(index) {
|
function playVideoAtIndex(index) {
|
||||||
if (index < 0 || index >= videoSequence.length) return;
|
if (index < 0 || index >= videoSequence.length) return;
|
||||||
|
|
||||||
@ -60,9 +96,8 @@ function playVideoAtIndex(index) {
|
|||||||
videoPlayer.play();
|
videoPlayer.play();
|
||||||
currentIndex = index;
|
currentIndex = index;
|
||||||
|
|
||||||
|
const currentLabel = videoSequence[index].split('/').pop().split('.')[0];
|
||||||
const currentChar = videoSequence[index].split('/').pop().split('.')[0];
|
document.getElementById('currentLetter').innerText = currentLabel.toUpperCase();
|
||||||
document.getElementById('currentLetter').innerText = currentChar.toUpperCase();
|
|
||||||
|
|
||||||
if (autoPlayEnabled) {
|
if (autoPlayEnabled) {
|
||||||
videoPlayer.onended = () => {
|
videoPlayer.onended = () => {
|
||||||
@ -78,11 +113,9 @@ function playVideoAtIndex(index) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
translateBtn.addEventListener('click', async () => {
|
translateBtn.addEventListener('click', async () => {
|
||||||
autoPlayEnabled = true;
|
autoPlayEnabled = true;
|
||||||
|
|
||||||
|
|
||||||
if (currentTranslationMode === 'words') {
|
if (currentTranslationMode === 'words') {
|
||||||
await loadVideoSequenceByWords();
|
await loadVideoSequenceByWords();
|
||||||
} else if (currentTranslationMode === 'letters') {
|
} else if (currentTranslationMode === 'letters') {
|
||||||
@ -91,24 +124,23 @@ translateBtn.addEventListener('click', async () => {
|
|||||||
|
|
||||||
if (videoSequence.length > 0) {
|
if (videoSequence.length > 0) {
|
||||||
playVideoAtIndex(currentIndex);
|
playVideoAtIndex(currentIndex);
|
||||||
|
} else {
|
||||||
|
statusText.innerText = 'No videos found for the entered text.';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
translateWordsBtn.addEventListener('click', () => {
|
translateWordsBtn.addEventListener('click', () => {
|
||||||
currentTranslationMode = 'words';
|
currentTranslationMode = 'words';
|
||||||
translateWordsBtn.classList.add('active');
|
translateWordsBtn.classList.add('active');
|
||||||
translateLettersBtn.classList.remove('active');
|
translateLettersBtn.classList.remove('active');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
translateLettersBtn.addEventListener('click', () => {
|
translateLettersBtn.addEventListener('click', () => {
|
||||||
currentTranslationMode = 'letters';
|
currentTranslationMode = 'letters';
|
||||||
translateLettersBtn.classList.add('active');
|
translateLettersBtn.classList.add('active');
|
||||||
translateWordsBtn.classList.remove('active');
|
translateWordsBtn.classList.remove('active');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
prevBtn.addEventListener('click', () => {
|
prevBtn.addEventListener('click', () => {
|
||||||
if (currentIndex > 0) {
|
if (currentIndex > 0) {
|
||||||
autoPlayEnabled = false;
|
autoPlayEnabled = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user