Practice Text
${sessionSettings.text}
`; 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(`Speed-Reading-Report.pdf`); } catch (error) { console.error("Failed to generate PDF:", error); alert("Sorry, there was an error creating the PDF file."); } finally { pdfContentArea.style.display = 'none'; } } // --- Event Listeners --- startBtn.addEventListener('click', startTrainer); pauseResumeBtn.addEventListener('click', togglePause); stopBtn.addEventListener('click', () => stopTrainer(false)); downloadPdfBtn.addEventListener('click', generatePdf); newSessionBtn.addEventListener('click', () => { wordDisplay.textContent = 'Get Ready...'; progressBar.style.width = '0%'; switchView('setup'); }); // --- Initial State --- function setInitialText() { textInput.value = "We the People of the United States, in Order to form a more perfect Union, establish Justice, insure domestic Tranquility, provide for the common defense, promote the general Welfare, and secure the Blessings of Liberty to ourselves and our Posterity, do ordain and establish this Constitution for the United States of America."; } setInitialText(); switchView('setup'); });