// Main application functionality class TranscriptionApp { constructor() { this.init(); } init() { this.setupEventListeners(); this.setupBackToTop(); } setupEventListeners() { // Transcription form submission const form = document.getElementById('transcription-form'); if (form) { form.addEventListener('submit', (e) => this.handleTranscription(e)); } // Copy button const copyBtn = document.getElementById('copy-btn'); if (copyBtn) { copyBtn.addEventListener('click', () => this.copyToClipboard()); } // Download button const downloadBtn = document.getElementById('download-btn'); if (downloadBtn) { downloadBtn.addEventListener('click', () => this.downloadTranscription()); } } setupBackToTop() { const backToTop = document.createElement('button'); backToTop.className = 'back-to-top'; backToTop.innerHTML = ''; document.body.appendChild(backToTop); // Show/hide back to top button window.addEventListener('scroll', () => { if (window.pageYOffset > 300) { backToTop.classList.add('visible'); } else { backToTop.classList.remove('visible'); } }); // Scroll to top when clicked backToTop.addEventListener('click', () => { window.scrollTo({ top: 0, behavior: 'smooth' }); }); // Update icons after adding new ones feather.replace(); } async handleTranscription(e) { e.preventDefault(); const videoUrl = document.getElementById('video-url').value; const language = document.getElementById('language').value; const format = document.getElementById('format').value; // Show loading state this.showLoading(); try { // Simulate API call (replace with actual API integration) const transcription = await this.simulateTranscription(videoUrl, language, format); // Display results this.displayResults(transcription); } catch (error) { this.showError('Failed to transcribe video. Please check the URL and try again.'); } } async simulateTranscription(videoUrl, language, format) { // Validate video URL if (!videoUrl || !videoUrl.includes('http')) { throw new Error('Please enter a valid video URL'); } // Simulate API processing time await new Promise(resolve => setTimeout(resolve, 2000)); // Mock transcription data based on format const mockTranscriptions = { txt: `Video Transcription Sample\n\n[00:00:00] Welcome to this demonstration of our transcription service.\n[00:00:05] This is a sample transcription showing how our AI converts video content into text.\n[00:00:15] You can use this text for subtitles, content creation, or accessibility purposes.\n[00:00:25] Thank you for using VidTranscribe Magic Wand!`, srt: `1\n00:00:00,000 --> 00:00:05,000\nWelcome to this demonstration of our transcription service.\n\n2\n00:00:05,000 --> 00:00:15,000\nThis is a sample transcription showing how our AI converts video content into text.\n\n3\n00:00:15,000 --> 00:00:25,000\nYou can use this text for subtitles, content creation, or accessibility purposes.\n\n4\n00:00:25,000 --> 00:00:30,000\nThank you for using VidTranscribe Magic Wand!`, vtt: `WEBVTT\n\n00:00:00.000 --> 00:00:05.000\nWelcome to this demonstration of our transcription service.\n\n00:00:05.000 --> 00:00:15.000\nThis is a sample transcription showing how our AI converts video content into text.\n\n00:00:15.000 --> 00:00:25.000\nYou can use this text for subtitles, content creation, or accessibility purposes.\n\n00:00:25.000 --> 00:00:30.000\nThank you for using VidTranscribe Magic Wand!`, json: JSON.stringify({ videoUrl: videoUrl, language: language, duration: "30 seconds", transcription: [ { start: "00:00:00", end: "00:00:05", text: "Welcome to this demonstration of our transcription service." }, { start: "00:00:05", end: "00:00:15", text: "This is a sample transcription showing how our AI converts video content into text." }, { start: "00:00:15", end: "00:00:25", text: "You can use this text for subtitles, content creation, or accessibility purposes." }, { start: "00:00:25", end: "00:00:30", text: "Thank you for using VidTranscribe Magic Wand!" } ] }, null, 2) }; return mockTranscriptions[format] || mockTranscriptions.txt; } showLoading() { const resultsSection = document.getElementById('results'); const outputDiv = document.getElementById('transcription-output'); resultsSection.classList.remove('hidden'); outputDiv.innerHTML = `
Transcribing your video...
This may take a few moments
${transcription}`;
} else {
outputDiv.innerHTML = `${message}