function detectType(url) { if (!url) return 'none'; try { new URL(url); } catch(e) { return 'none'; } const path = (new URL(url)).pathname.toLowerCase(); const ext = path.split('.').pop(); const imgs = ['jpg','jpeg','png','gif','webp','bmp','svg','avif']; const vids = ['mp4','webm','ogv','mov']; const auds = ['mp3','flac','wav','ogg','aac','opus','m4a']; if (imgs.includes(ext)) return 'image'; if (vids.includes(ext)) return 'video'; if (auds.includes(ext)) return 'audio'; if (/(?:youtube\.com\/watch\?.*v=|youtu\.be\/)([A-Za-z0-9_-]{11})/.test(url)) return 'youtube'; if (/vimeo\.com\/(\d+)/.test(url)) return 'vimeo'; return 'link'; } function getYTId(url) { const m = url.match(/(?:v=|youtu\.be\/)([A-Za-z0-9_-]{11})/); return m ? m[1] : null; } function getVimeoId(url) { const m = url.match(/vimeo\.com\/(\d+)/); return m ? m[1] : null; } function updateBadge(type) { const b = document.getElementById('type-badge'); b.textContent = type; } function updatePreview(url) { const body = document.getElementById('preview-body'); if (!url) { body.innerHTML = '
// no url set
'; return; } const type = detectType(url); const safeUrl = url.replace(/"/g, '%22'); let html = ``; if (type === 'image') { html += `