diff --git a/public/js/script.js b/public/js/script.js index 1617774..afeca25 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -39,4 +39,27 @@ document.getElementById('uploadForm').addEventListener('submit', async function generateBtn.textContent = 'Generate Cover Letter'; } +}); + +document.getElementById('downloadBtn').addEventListener('click', async function() { + const coverLetterText = document.getElementById('coverLetterOutput').value; + + try { + const response = await fetch('/generate/download', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ coverLetterText }) + }); + + const result = await response.json(); + if (result.downloadLink) { + window.location.href = result.downloadLink; + } else { + alert('Error downloading document.') + } + } catch (error) { + console.error('Error:', error); + alert('Failed to download document.') + } + }); \ No newline at end of file