Online Commonly Confused Words Identifier
Analysis Report
Analyzed Text
Summary of Issues
Suggestion: ${issue.details.suggestion}
Explanation: ${issue.details.explanation}
`; summaryListContainer.appendChild(summaryItem); }); } else { summaryListContainer.innerHTML = `No commonly confused words were identified in your text.
`;
}
resultsSection.classList.remove('hidden');
};
// --- PDF Generation Function ---
const generatePdf = () => {
// Use the globally available jsPDF and html2canvas objects
const { jsPDF } = window.jspdf;
// Show a temporary message while generating PDF
const originalButtonText = downloadPdfBtn.innerHTML;
downloadPdfBtn.innerHTML = 'Generating PDF...';
downloadPdfBtn.disabled = true;
html2canvas(pdfContent, {
scale: 2, // Increase scale for better resolution
useCORS: true,
onclone: (document) => {
// This function is called when html2canvas clones the DOM
// We can make temporary style changes here for the PDF output
const clonedContent = document.getElementById('pdf-content');
if(clonedContent) {
// Example: Remove tooltips from the PDF to prevent rendering issues
clonedContent.querySelectorAll('.tooltip-text').forEach(tip => tip.style.display = 'none');
}
}
}).then(canvas => {
const imgData = canvas.toDataURL('image/png');
const pdf = new jsPDF({
orientation: 'portrait',
unit: 'px',
format: [canvas.width, canvas.height]
});
pdf.addImage(imgData, 'PNG', 0, 0, canvas.width, canvas.height);
pdf.save('Confused_Words_Analysis.pdf');
// Restore button state
downloadPdfBtn.innerHTML = originalButtonText;
downloadPdfBtn.disabled = false;
}).catch(err => {
console.error("Error generating PDF:", err);
alert("Sorry, there was an error creating the PDF. Please try again.");
// Restore button state
downloadPdfBtn.innerHTML = originalButtonText;
downloadPdfBtn.disabled = false;
});
};
// --- Event Listeners ---
checkTextBtn.addEventListener('click', analyzeText);
downloadPdfBtn.addEventListener('click', generatePdf);
});
