Investment Newsletter Automation System

Investment Newsletter Automation System

General Sections

${data.rating}

`; } if (newsletterState.sections.news) { html += `

Recent News

    ${data.news.map(item => `
  • ${item}
  • `).join('')}
`; } html += `
`; }); } newsletterPreview.innerHTML = html; } async function downloadPdf() { const content = document.getElementById('pdf-content'); downloadPdfBtn.textContent = 'Generating...'; downloadPdfBtn.disabled = true; try { const canvas = await html2canvas(content, { scale: 2, backgroundColor: '#f3f4f6' }); const imgData = canvas.toDataURL('image/png'); const { jsPDF } = window.jspdf; const pdf = new jsPDF({ orientation: 'p', unit: 'px', format: [canvas.width, canvas.height] }); pdf.addImage(imgData, 'PNG', 0, 0, canvas.width, canvas.height); pdf.save(`${newsletterState.title.replace(/\s+/g, '-')}.pdf`); } catch (error) { console.error("PDF generation failed:", error); alert("Could not generate PDF. Please try again."); } finally { downloadPdfBtn.textContent = 'Download Newsletter as PDF'; downloadPdfBtn.disabled = false; } } function formatDate(dateString) { if (!dateString) return 'N/A'; const options = { year: 'numeric', month: 'long', day: 'numeric' }; return new Date(dateString + 'T00:00:00').toLocaleDateString('en-US', options); } // --- INITIALIZATION & EVENT LISTENERS --- function initialize() { // Set default date document.getElementById('newsletter-date').valueAsDate = new Date(); // Add default tickers newsletterState.tickers = ['AAPL', 'MSFT']; renderTickerList(); updateStateFromInputs(); switchTab(0); // Start on the first tab // Event Listeners tabs.forEach((tab, index) => { tab.addEventListener('click', () => switchTab(index)); }); prevBtn.addEventListener('click', () => switchTab(currentTab - 1)); nextBtn.addEventListener('click', () => switchTab(currentTab + 1)); addTickerBtn.addEventListener('click', addTicker); tickerInput.addEventListener('keyup', (e) => { if (e.key === 'Enter') addTicker(); }); downloadPdfBtn.addEventListener('click', downloadPdf); // Auto-update preview when inputs change document.getElementById('tool-container').addEventListener('input', () => { if (currentTab === 2) { generateNewsletterPreview(); } }); } initialize(); });
Scroll to Top