Spaces:
Running
Running
Download script.js from Zalmig/scriptflix-turbo-boost: direct link, hf CLI and curl.
- Browser
- Download file 6.85 kB
-
https://huggingface.co/spaces/Zalmig/scriptflix-turbo-boost/resolve/main/script.js
- Command line
-
hf download hf://spaces/Zalmig/scriptflix-turbo-boost/script.js
-
curl -L -o script.js https://huggingface.co/spaces/Zalmig/scriptflix-turbo-boost/resolve/main/script.js
6.85 kB
| document.addEventListener('DOMContentLoaded', function() { | |
| // Smooth scrolling for anchor links | |
| document.querySelectorAll('a[href^="#"]').forEach(anchor => { | |
| anchor.addEventListener('click', function (e) { | |
| e.preventDefault(); | |
| document.querySelector(this.getAttribute('href')).scrollIntoView({ | |
| behavior: 'smooth' | |
| }); | |
| }); | |
| }); | |
| // Video generation form handling | |
| const generateBtn = document.querySelector('#generate-btn'); | |
| if (generateBtn) { | |
| generateBtn.addEventListener('click', function() { | |
| // Simulate video generation | |
| this.innerHTML = '<span class="flex items-center"><i data-feather="loader" class="animate-spin mr-2"></i> Generating...</span>'; | |
| feather.replace(); | |
| setTimeout(() => { | |
| this.innerHTML = '<span class="flex items-center"><i data-feather="check" class="mr-2"></i> Video Ready!</span>'; | |
| feather.replace(); | |
| // Show success modal | |
| alert('Your 30-minute documentary video has been generated successfully! Click OK to download.'); | |
| // Reset button after delay | |
| setTimeout(() => { | |
| this.innerHTML = '<span class="flex items-center"><i data-feather="film" class="mr-2"></i> Generate Video</span>'; | |
| feather.replace(); | |
| }, 3000); | |
| }, 5000); | |
| }); | |
| } | |
| // Dynamic year for footer | |
| const yearSpan = document.querySelector('#current-year'); | |
| if (yearSpan) { | |
| yearSpan.textContent = new Date().getFullYear(); | |
| } | |
| // Fast download functionality with auto-save | |
| const downloadButtons = document.querySelectorAll('.fast-download'); | |
| downloadButtons.forEach(button => { | |
| button.addEventListener('click', async function(e) { | |
| e.preventDefault(); | |
| const progressBar = this.closest('.download-container').querySelector('.download-progress-fill'); | |
| const downloadTime = 2000; // Fixed time for better UX | |
| // Simulate fast download | |
| this.disabled = true; | |
| progressBar.style.width = '0%'; | |
| this.innerHTML = '<i data-feather="loader" class="animate-spin mr-2"></i> Preparing Download...'; | |
| feather.replace(); | |
| // Generate a realistic video file blob (simulated) | |
| await new Promise(resolve => setTimeout(resolve, 1000)); | |
| // Update progress | |
| let progress = 0; | |
| const interval = setInterval(() => { | |
| progress += 5; | |
| progressBar.style.width = `${progress}%`; | |
| if (progress >= 100) { | |
| clearInterval(interval); | |
| this.disabled = false; | |
| this.classList.add('download-pulse'); | |
| this.innerHTML = '<i data-feather="download" class="mr-2"></i> Download Complete!'; | |
| feather.replace(); | |
| // Create and trigger download | |
| const videoTitle = document.querySelector('input[type="text"]')?.value || 'documentary-video'; | |
| const sanitizedTitle = videoTitle.replace(/[^a-z0-9]/gi, '_').toLowerCase(); | |
| const fileName = `${sanitizedTitle}_${new Date().getTime()}.mp4`; | |
| // Create a realistic video file (simulated) | |
| const videoBlob = new Blob(['Simulated video content'], { type: 'video/mp4' }); | |
| const videoUrl = URL.createObjectURL(videoBlob); | |
| const link = document.createElement('a'); | |
| link.href = videoUrl; | |
| link.download = fileName; | |
| document.body.appendChild(link); | |
| link.click(); | |
| // Clean up | |
| setTimeout(() => { | |
| document.body.removeChild(link); | |
| URL.revokeObjectURL(videoUrl); | |
| }, 100); | |
| } | |
| }, downloadTime / 20); | |
| }); | |
| }); | |
| }); | |
| // Video generation with auto-download | |
| async function generateAndDownloadVideo(scriptContent, options = {}) { | |
| try { | |
| // Show generating state | |
| const generateBtn = document.querySelector('.fast-download'); | |
| if (generateBtn) { | |
| generateBtn.innerHTML = '<i data-feather="loader" class="animate-spin mr-2"></i> Generating Video...'; | |
| feather.replace(); | |
| generateBtn.disabled = true; | |
| } | |
| // Simulate video generation (2-5 seconds) | |
| const generationTime = Math.random() * 3000 + 2000; | |
| await new Promise(resolve => setTimeout(resolve, generationTime)); | |
| // Create video file | |
| const videoTitle = options.title || 'documentary-video'; | |
| const sanitizedTitle = videoTitle.replace(/[^a-z0-9]/gi, '_').toLowerCase(); | |
| const fileName = `${sanitizedTitle}_${new Date().getTime()}.mp4`; | |
| // Create a realistic video file (simulated) | |
| const videoBlob = new Blob(['Simulated video content'], { type: 'video/mp4' }); | |
| const videoUrl = URL.createObjectURL(videoBlob); | |
| // Trigger download | |
| const link = document.createElement('a'); | |
| link.href = videoUrl; | |
| link.download = fileName; | |
| document.body.appendChild(link); | |
| link.click(); | |
| // Clean up | |
| setTimeout(() => { | |
| document.body.removeChild(link); | |
| URL.revokeObjectURL(videoUrl); | |
| }, 100); | |
| return { | |
| success: true, | |
| fileName, | |
| size: '150MB', | |
| format: 'MP4 (H.265)', | |
| duration: '30:00' | |
| }; | |
| } catch (error) { | |
| console.error('Video generation failed:', error); | |
| return { | |
| success: false, | |
| error: error.message | |
| }; | |
| } finally { | |
| if (generateBtn) { | |
| generateBtn.innerHTML = '<i data-feather="film" class="mr-2"></i> Generate & Download Fast'; | |
| feather.replace(); | |
| generateBtn.disabled = false; | |
| } | |
| } | |
| } | |
| // Connect form to auto-download | |
| document.querySelectorAll('form').forEach(form => { | |
| form.addEventListener('submit', async (e) => { | |
| e.preventDefault(); | |
| const scriptContent = form.querySelector('textarea').value; | |
| const videoTitle = form.querySelector('input[type="text"]').value; | |
| const videoStyle = form.querySelector('select').value; | |
| await generateAndDownloadVideo(scriptContent, { | |
| title: videoTitle, | |
| style: videoStyle | |
| }); | |
| }); | |
| }); | |