Essay Writing Assistant
Structure your arguments, draft your essay, and refine your final text.
Structure Your Essay
Main Body Paragraphs
Draft Your Essay
Your Outline:
Word Count: 0
Final Review
Thesis: ${thesisStatement}
`; document.querySelectorAll('#main-points-container .point-topic').forEach((topic, index) => { outlineHTML += `Point ${index + 1}: ${topic.value || 'Not specified'}
`; }); draftOutlineDisplay.innerHTML = outlineHTML; } // For Tab 3: Final Review Display const finalTitle = getElement('final-title'); const finalThesis = getElement('final-thesis'); const finalBody = getElement('final-body'); const draftText = getElement('essay-draft')?.value; if (finalTitle) finalTitle.textContent = essayTitle; if (finalThesis) finalThesis.textContent = thesisStatement; if (finalBody && draftText) { // Convert newlines in textarea totags for better formatting finalBody.innerHTML = draftText.split('\n').filter(p => p.trim() !== '').map(p => `
${p}
`).join(''); } else if (finalBody) { finalBody.innerHTML = 'Your essay draft will appear here once you write it in the "Drafting Assistant" tab.
'; } }; /** * Updates the word count for the essay draft textarea. */ const updateWordCount = () => { if (!essayDraft || !wordCountDisplay) return; const text = essayDraft.value.trim(); const words = text.length > 0 ? text.split(/\s+/).length : 0; wordCountDisplay.textContent = `Word Count: ${words}`; }; /** * Generates and downloads a PDF of the final essay. */ const downloadPDF = () => { const pdfContent = getElement('pdf-content-wrapper'); const finalTitle = getElement('final-title'); if (!pdfContent || !finalTitle) { alert('Could not find content to generate PDF.'); return; } // Use html2canvas to render the div to a canvas html2canvas(pdfContent, { scale: 2 }).then(canvas => { const imgData = canvas.toDataURL('image/png'); // Initialize jsPDF const { jsPDF } = window.jspdf; const pdf = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const pdfHeight = pdf.internal.pageSize.getHeight(); const canvasWidth = canvas.width; const canvasHeight = canvas.height; const ratio = canvasWidth / canvasHeight; const imgWidth = pdfWidth - 20; // with margin const imgHeight = imgWidth / ratio; pdf.addImage(imgData, 'PNG', 10, 10, imgWidth, imgHeight); const fileName = (finalTitle.textContent.replace(/ /g, '_') || 'Essay') + '.pdf'; pdf.save(fileName); }); }; // --- Event Listeners --- tabs.forEach(tab => { tab.addEventListener('click', () => { const tabNum = parseInt(tab.dataset.tab); if (tabNum > currentTab) { // Allow moving forward only if "Next" would if (currentTab < 3) { prepareDataForNextTabs(); currentTab = tabNum; } } else { currentTab = tabNum; } updateTabView(); }); }); if (prevBtn) { prevBtn.addEventListener('click', () => { if (currentTab > 1) { currentTab--; updateTabView(); } }); } if (nextBtn) { nextBtn.addEventListener('click', () => { if (currentTab < 3) { prepareDataForNextTabs(); currentTab++; updateTabView(); } }); } if (addPointBtn) { addPointBtn.addEventListener('click', addMainPoint); } if (essayDraft) { essayDraft.addEventListener('input', updateWordCount); } if (downloadPdfBtn) { downloadPdfBtn.addEventListener('click', downloadPDF); } // --- Initial Setup --- addMainPoint(); // Start with one point addMainPoint(); // And a second one addMainPoint(); // And a third one updateTabView(); // Set initial view });