Professional Email Assistant

Professional Email Assistant

Craft clear, effective, and polished emails with confidence.

Email Composer

Choose a Template

Analysis & Suggestions

Tone Analysis

Write an email in the composer to see the tone analysis.

Subject Line Suggestions

Based on your email content.

No suggestions yet. Write an email first.

Write more to generate suggestions.

`; } } document.getElementById('analysis-content').addEventListener('click', e => { if (e.target.classList.contains('subject-suggestion')) { subjectInput.value = e.target.textContent; emailData.subject = e.target.textContent; switchTab(0); } }); // --- TEMPLATES LOGIC --- function renderTemplates() { templateList.innerHTML = emailTemplates.map(template => `

${template.name}

${template.subject}

`).join(''); } templateList.addEventListener('click', e => { const templateCard = e.target.closest('div[data-subject]'); if (templateCard) { subjectInput.value = templateCard.dataset.subject; bodyInput.value = templateCard.dataset.body; emailData.subject = templateCard.dataset.subject; emailData.body = templateCard.dataset.body; runAnalysis(); switchTab(0); } }); // --- TAB LOGIC --- let currentTabIndex = 0; const tabs = ['composer', 'templates', 'analysis']; function switchTab(tabIndex) { currentTabIndex = tabIndex; tabBtns.forEach((btn, index) => { const tabName = btn.dataset.tab; document.getElementById(`${tabName}-content`).classList.toggle('active', index === tabIndex); btn.classList.toggle('active', index === tabIndex); }); prevTabBtn.disabled = tabIndex === 0; nextTabBtn.disabled = tabIndex === tabs.length - 1; } tabBtns.forEach((button, index) => button.addEventListener('click', () => switchTab(index))); prevTabBtn.addEventListener('click', () => { if (currentTabIndex > 0) switchTab(currentTabIndex - 1); }); nextTabBtn.addEventListener('click', () => { if (currentTabIndex < tabs.length - 1) switchTab(currentTabIndex + 1); }); // --- PDF GENERATION --- async function generatePdfReport() { const button = downloadPdfBtn; const originalText = button.textContent; button.disabled = true; button.textContent = 'Generating...'; const reportHtml = `

Email Draft

From:${emailData.from || 'N/A'}
To:${emailData.to || 'N/A'}
Date:${new Date().toLocaleDateString("en-US")}
Subject:${emailData.subject || 'N/A'}
${emailData.body || 'No content.'}
`; const pdfTemplate = document.getElementById('pdf-template'); pdfTemplate.innerHTML = reportHtml; pdfTemplate.style.position = 'absolute'; pdfTemplate.style.left = '-9999px'; pdfTemplate.classList.remove('invisible'); try { const { jsPDF } = window.jspdf; const canvas = await html2canvas(pdfTemplate.querySelector('.pdf-report-container'), { scale: 2, useCORS: true }); const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF({ orientation: 'p', unit: 'pt', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const pdfHeight = (canvas.height * pdfWidth) / canvas.width; pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight); pdf.save(`Email_Draft_${(emailData.subject || 'Untitled').replace(/\s+/g, '_')}.pdf`); } catch(e) { console.error('PDF Generation Error:', e); alert('Failed to generate PDF. See console for details.'); } finally { button.disabled = false; button.textContent = originalText; pdfTemplate.innerHTML = ''; pdfTemplate.classList.add('invisible'); } } downloadPdfBtn.addEventListener('click', generatePdfReport); // --- INITIALIZATION --- switchTab(0); renderTemplates(); });
Scroll to Top