`;
}
function getYouTubeId(url) {
const regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/;
const match = url.match(regExp);
return (match && match[2].length === 11) ? match[2] : null;
}
function displayVideoPreview(videoId) {
elements.videoPreview.innerHTML = ``;
}
function updateDownloadButton() {
const format = elements.captionFormat.value;
elements.downloadFormatText.textContent = `Download .${format}`;
}
// --- File Downloads ---
function downloadFormatFile() {
const format = elements.captionFormat.value;
const content = elements.captionsOutput.value;
if (!content) return;
const blob = new Blob([content], { type: 'text/plain;charset=utf-8' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `captions.${format}`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
function generatePdf() {
const captions = elements.captionsOutput.value;
if (!captions) return;
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
doc.setFont('helvetica', 'bold');
doc.setFontSize(18);
doc.text('Video Caption Report', doc.internal.pageSize.getWidth() / 2, 20, { align: 'center' });
doc.setFontSize(11);
doc.setTextColor(100);
doc.text(`Report Date: ${new Date().toLocaleDateString('en-US')}`, 14, 30);
doc.text(`Video Topic: ${elements.videoTopic.value}`, 14, 37);
doc.autoTable({
startY: 45,
head: [['Generated Captions']],
body: [[captions]],
theme: 'grid',
headStyles: { fillColor: '#111827' },
styles: { font: 'courier', cellPadding: 3 },
});
doc.save('video-caption-report.pdf');
}
initialize();
});
