Relationship Advice Blog Post Generator
Create insightful and empathetic advice articles.
Article Foundation
The Core Issue
Actionable Advice
Generated Blog Post
Copied to clipboard!
${data.conclusion}
`; } function showMessage() { messageBox.classList.remove('opacity-0', 'translate-y-10'); messageBox.classList.add('opacity-100', 'translate-y-0'); setTimeout(() => { messageBox.classList.remove('opacity-100', 'translate-y-0'); messageBox.classList.add('opacity-0', 'translate-y-10'); }, 2000); } function generateAdvicePdf() { const { jsPDF } = window.jspdf; const pdf = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' }); const data = getFormData(); const pageW = pdf.internal.pageSize.getWidth(); const pageH = pdf.internal.pageSize.getHeight(); const margin = 20; const contentWidth = pageW - (margin * 2); let y = 0; const lineH = 7; const addHeaderFooter = () => { const pageCount = pdf.internal.getNumberOfPages(); for (let i = 1; i <= pageCount; i++) { pdf.setPage(i); pdf.setFontSize(9); pdf.setTextColor('#9ca3af'); // gray-400 if (i > 1) { pdf.text(data.title, margin, 12); } pdf.text(`Page ${i}`, pageW - margin, pageH - 10, { align: 'right' }); } }; const checkBreak = (needed = 20) => { if (y + needed > pageH - margin) { pdf.addPage(); y = margin; } }; const addText = (text, options = {}) => { const { size=11, style='normal', color='#374151', indent=0, spacing=1 } = options; if (!text && text !== '') return; checkBreak(15); pdf.setFontSize(size); pdf.setFont('times', style); pdf.setTextColor(color); const splitText = pdf.splitTextToSize(text, contentWidth - indent); pdf.text(splitText, margin + indent, y); y += (splitText.length * lineH * 0.75) + (lineH * spacing); }; const addSectionHeader = (title) => { y += lineH * 1.5; checkBreak(20); pdf.setFontSize(16); pdf.setFont('helvetica', 'bold'); pdf.setTextColor('#be185d'); // pink-700 pdf.text(title, margin, y); y += lineH * 1.5; }; // --- Build PDF Document --- // Page 1: Title Page pdf.setFillColor('#fdf2f8'); // pink-50 pdf.rect(0, 0, pageW, pageH, 'F'); pdf.setFontSize(26); pdf.setFont('helvetica', 'bold'); pdf.setTextColor('#4b5563'); const titleLines = pdf.splitTextToSize(data.title, contentWidth - 20); pdf.text(titleLines, pageW / 2, 100, { align: 'center' }); pdf.setFontSize(12); pdf.setFont('helvetica', 'normal'); pdf.setTextColor('#6b7280'); pdf.text(`A Guide for ${data.audience}`, pageW / 2, 115 + (titleLines.length * 10), { align: 'center' }); pdf.addPage(); y = margin; // Introduction addSectionHeader("Introduction"); addText(data.introduction); // Problem addSectionHeader("Understanding the Challenge"); addText(data.problem); // Advice Points if (data.advicePoints.length > 0) { addSectionHeader("Actionable Steps"); data.advicePoints.forEach((item, index) => { checkBreak(30); addText(`${index + 1}. ${item.title}`, { style: 'bold', size: 14, color: '#374151', spacing: 0.5 }); addText(item.description, {spacing: 1.5, indent: 5}); }); } // Conclusion addSectionHeader("Final Thoughts"); addText(data.conclusion); addHeaderFooter(); pdf.save(`Advice_${data.title.replace(/\s+/g, '_').substring(0,20)}.pdf`); } // --- Event Listeners & Init --- tabs.forEach(tab => tab.addEventListener('click', () => goToTab(parseInt(tab.dataset.tab)))); prevButton.addEventListener('click', () => goToTab(currentTab - 1)); nextButton.addEventListener('click', () => goToTab(currentTab + 1)); copyButton.addEventListener('click', () => { const preview = document.getElementById('report-preview-container'); if (preview) { navigator.clipboard.writeText(preview.innerText).then(() => { showMessage(); }).catch(err => console.error('Copy failed: ', err)); } }); pdfDownloadButton.addEventListener('click', generateAdvicePdf); addAdviceButton.addEventListener('click', addAdviceItem); // Add one initial advice item addAdviceItem(); updateTabUI(); });