27 lines
1.6 KiB
JavaScript
27 lines
1.6 KiB
JavaScript
|
|
// ═══════════════════════════════════════════════════════
|
||
|
|
// YouTube
|
||
|
|
// ═══════════════════════════════════════════════════════
|
||
|
|
async function fetchYouTube() {
|
||
|
|
const url = document.getElementById('ytInput').value.trim();
|
||
|
|
if (!url) return setStatus('ytStatus','error','Enter a YouTube URL.');
|
||
|
|
setStatus('ytStatus','info','Fetching...');
|
||
|
|
const d = await apiPost('/api/youtube/info', { url });
|
||
|
|
if (d.success) {
|
||
|
|
document.getElementById('ytThumb').src = d.thumbnail;
|
||
|
|
document.getElementById('ytThumb').onerror = function() { this.src = d.thumbnailHQ; };
|
||
|
|
document.getElementById('ytTitle').textContent = d.title;
|
||
|
|
document.getElementById('ytAuthor').textContent = d.author;
|
||
|
|
document.getElementById('ytAuthor').href = d.authorUrl;
|
||
|
|
document.getElementById('ytThumbMax').textContent = d.thumbnail;
|
||
|
|
document.getElementById('ytThumbHQ').textContent = d.thumbnailHQ;
|
||
|
|
document.getElementById('ytEmbed').value = `<iframe width="560" height="315" src="${d.embedUrl}" frameborder="0" allowfullscreen></iframe>`;
|
||
|
|
document.getElementById('ytWatch').href = d.watchUrl;
|
||
|
|
document.getElementById('ytResult').classList.add('visible');
|
||
|
|
setStatus('ytStatus','success','Fetched ✓');
|
||
|
|
} else { document.getElementById('ytResult').classList.remove('visible'); setStatus('ytStatus','error', d.error); }
|
||
|
|
}
|
||
|
|
|
||
|
|
// Keyboard shortcut
|
||
|
|
document.getElementById('ytInput').addEventListener('keydown', e => { if(e.key==='Enter') fetchYouTube(); });
|
||
|
|
|