document.getElementById('downloadForm').addEventListener('submit', function(event) { event.preventDefault(); const videoUrl = document.getElementById('videoUrl').value; downloadVideo(videoUrl); }); async function downloadVideo(url) { const resultDiv = document.getElementById('result'); resultDiv.innerHTML = `

Processing...

`; try { const response = await fetch('', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, body: `action=download_tiktok_video&url=${encodeURIComponent(url)}` }); const data = await response.json(); if (data.success) { window.location.href = data.download_url; // Redirect to download link } else { resultDiv.innerHTML = `

Error: ${data.error}

`; } } catch (error) { resultDiv.innerHTML = `

Error: ${error.message}

`; } }