`).join('');
};
renderFeed('news-feed', analysisResults.newsFeed);
renderFeed('social-feed', analysisResults.socialFeed);
}
// --- PDF GENERATION ---
async function generatePdfReport() {
downloadPdfBtn.disabled = true;
downloadPdfBtn.textContent = 'Generating...';
const renderTableRows = (data) => data.map(item => `${item.headline || item.post} ${item.score.toFixed(0)} `).join('');
const reportHtml = `
`;
const pdfTemplate = document.getElementById('pdf-template');
pdfTemplate.innerHTML = reportHtml;
pdfTemplate.classList.remove('invisible');
try {
const { jsPDF } = window.jspdf;
const canvas = await html2canvas(pdfTemplate.querySelector('.pdf-page'), { scale: 2 });
const imgData = canvas.toDataURL('image/png');
const pdf = new jsPDF({ orientation: 'p', unit: 'pt', format: 'a4' });
const pdfWidth = pdf.internal.pageSize.getWidth(), pdfHeight = (canvas.height * pdfWidth) / canvas.width;
pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight);
pdf.save(`Market_Sentiment_Report_${dateInput.value}.pdf`);
} catch (e) { console.error('PDF Generation Error:', e); } finally {
downloadPdfBtn.disabled = false;
downloadPdfBtn.textContent = 'Download PDF Report';
pdfTemplate.classList.add('invisible');
pdfTemplate.innerHTML = '';
}
}
// --- EVENT LISTENERS ---
dateInput.addEventListener('change', analyzeSentiment);
downloadPdfBtn.addEventListener('click', generatePdfReport);
// --- INITIALIZATION ---
dateInput.value = new Date().toISOString().split('T')[0];
analyzeSentiment();
switchTab(0);
});
Market Intelligence Briefing
Report for: ${dateInput.value}
OVERALL SENTIMENT
${(analysisResults.overallSentiment > 65 ? 'Greed' : (analysisResults.overallSentiment < 35 ? 'Fear' : 'Neutral'))} (${analysisResults.overallSentiment.toFixed(0)})
NEWS SENTIMENT
${analysisResults.newsScore.toFixed(0)}
VOLATILITY (VIX)
${analysisResults.vix.toFixed(2)}
Key News Drivers
| Headline | Sentiment Score |
|---|
Key Social Media Trends
| Post | Sentiment Score |
|---|
