Science Communication Strategy Planner
Configure details in the Data Configuration tab and click "Generate Strategy."
Error: Please fill in the Topic and Core Message fields.
'; return; } var reportHtml = `Science Communication Strategy: ${data.topic}
1. Core Context
Objective: ${formatText(data.objective)}
Scientific Consensus: ${formatText(data.consensus)}
2. Message Framework
Core Message: ${data.coreMessage}
Values Stressed: ${formatText(data.values)}
3. Audience Segmentation
Primary Supporters (Reinforcement Strategy)
${parseList(data.supporters)}Secondary Skeptics (Persuasion Strategy)
${parseList(data.skeptics)}4. Pre-emptive Disinformation Planning
Counter-Argument 1: ${data.arg1}
Planned Rebuttal: ${formatText(data.rebuttal1)}
Counter-Argument 2: ${data.arg2}
Planned Rebuttal: ${formatText(data.rebuttal2)}
`;
strategyContentDiv.innerHTML = reportHtml;
};
generateBtn.addEventListener("click", function() {
generateStrategy();
showTab(1); // Switch to Dashboard
});
// --- PDF Download ---
pdfBtn.addEventListener("click", function() {
var jsPDF = window.jspdf.jsPDF;
var topicSlug = topicInput.value.replace(/[^a-zA-Z0-9\s]/g, '').replace(/\s/g, '_').substring(0, 30) || 'Strategy';
var fileName = `${topicSlug}_Communication_Strategy.pdf`;
html2canvas(exportArea, {
scale: 2,
useCORS: true,
backgroundColor: '#ffffff'
}).then(function(canvas) {
var imgData = canvas.toDataURL('image/png');
var doc = new jsPDF({
orientation: 'p',
unit: 'pt',
format: 'letter'
});
var pdfWidth = doc.internal.pageSize.getWidth();
var pdfHeight = doc.internal.pageSize.getHeight();
var imgProps = doc.getImageProperties(imgData);
var imgWidth = imgProps.width;
var imgHeight = imgProps.height;
var margin = 40;
var usableWidth = pdfWidth - (2 * margin);
var ratio = usableWidth / imgWidth;
var scaledHeight = imgHeight * ratio;
// Handle multi-page if content exceeds page height
if (scaledHeight > pdfHeight - (2 * margin)) {
var pageHeight = pdfHeight - (2 * margin);
var heightLeft = scaledHeight;
var position = 0;
while (heightLeft > 0) {
doc.addImage(imgData, 'PNG', margin, position + margin, usableWidth, scaledHeight);
heightLeft -= pageHeight;
position -= pageHeight;
if (heightLeft > 0) {
doc.addPage();
}
}
} else {
// Single page
doc.addImage(imgData, 'PNG', margin, margin, usableWidth, scaledHeight);
}
doc.save(fileName);
}).catch(function(err) {
console.error("SCP PDF Error:", err);
// alert("An error occurred while generating the PDF."); // Per spec
});
});
// --- Initial Load ---
generateStrategy(); // Generate with defaults
showTab(0); // Start on Config tab
});
