`).join('');
switchView('results');
};
// --- PDF Generation ---
async function generatePdf() {
pdfContentArea.innerHTML = `
`).join('')}
`;
pdfContentArea.style.display = 'block';
pdfContentArea.style.position = 'absolute';
pdfContentArea.style.left = '-9999px';
pdfContentArea.style.width = '800px';
try {
const canvas = await html2canvas(pdfContentArea, { scale: 2 });
const imgData = canvas.toDataURL('image/png');
const { jsPDF } = window.jspdf;
const pdf = new jsPDF({ orientation: 'portrait', unit: 'px', format: 'a4' });
const pdfWidth = pdf.internal.pageSize.getWidth();
const imgHeight = canvas.height * pdfWidth / canvas.width;
pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, imgHeight);
pdf.save(`Comprehension-Test-Report.pdf`);
} catch (error) {
console.error("PDF generation failed:", error);
alert("Could not generate PDF.");
} finally {
pdfContentArea.style.display = 'none';
}
}
const showError = (msg) => {
setupError.textContent = msg;
setupError.style.display = 'block';
};
const hideError = () => {
setupError.style.display = 'none';
};
// --- Event Listeners ---
generateTestBtn.addEventListener('click', generateTest);
submitTestBtn.addEventListener('click', submitTest);
downloadReportBtn.addEventListener('click', generatePdf);
startOverBtn.addEventListener('click', () => switchView('setup'));
// --- Initial State ---
textInput.value = "The Industrial Revolution, which began in Great Britain in the late 18th century, was a period of major industrialization that saw the mechanization of agriculture and textile manufacturing and a revolution in power, including steam ships and railroads. This period had a profound effect on the social, economic, and cultural conditions of the time. It marked a major turning point in history; almost every aspect of daily life was influenced in some way.";
switchView('setup');
});
Comprehension Test Report
${finalScoreEl.textContent}
Results Breakdown
${testData.map((q, index) => `${index + 1}. ${q.question_text}
Your answer: ${q.studentAnswer || "No answer"}
${!q.isCorrect ? `Correct answer: ${q.correct_answer}
` : ''}