Reading & Proofreading Tool

Reading & Proofreading Tool

Generate comprehension quizzes or proofread your text.

Enter Text Passage

Quiz Results

Your results will be displayed here after you complete the quiz.

Enter Text to Proofread

Explanation: ${q.explanation}

`; resultsContainer.appendChild(resultBlock); }); const scoreBlock = document.createElement('div'); scoreBlock.className = 'p-4 rounded-lg bg-blue-100 text-blue-800 text-center text-xl font-bold'; scoreBlock.textContent = `Your Final Score: ${score} out of ${quizData.length}`; resultsContainer.prepend(scoreBlock); quizPdfDownloadBtn.classList.remove('hidden'); }; // --- Proofreading Logic --- const handleProofread = async () => { const text = proofreadInput.value.trim(); if (!text) { showMessage('Please enter text to proofread.'); return; } clearMessage(); setLoadingState(proofreadBtn, proofreadBtnText, proofreadBtnLoader, true); proofreadResultContainer.classList.add('hidden'); proofreadPdfDownloadBtn.classList.add('hidden'); const prompt = `Act as a proofreading assistant. Analyze the following text for errors in spelling, grammar, and punctuation. Provide a fully corrected version of the text. Also, provide a list of the changes made, categorizing each change and explaining the reasoning. Text: "${text}"`; const payload = { contents: [{ parts: [{ text: prompt }] }], generationConfig: { responseMimeType: "application/json", responseSchema: { type: "OBJECT", properties: { correctedText: { type: "STRING" }, changes: { type: "ARRAY", items: { type: "OBJECT", properties: { type: { type: "STRING", enum: ["Spelling", "Grammar", "Punctuation", "Style"] }, original: { type: "STRING" }, suggestion: { type: "STRING" }, explanation: { type: "STRING" } }, required: ["type", "original", "suggestion", "explanation"] } } }, required: ["correctedText", "changes"] } } }; try { const apiKey = ""; const apiUrl = `https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-preview-05-20:generateContent?key=${apiKey}`; const response = await fetch(apiUrl, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload) }); if (!response.ok) throw new Error(`API Error: ${response.statusText}`); const result = await response.json(); const contentPart = result.candidates?.[0]?.content?.parts?.[0]; if (contentPart?.text) { const parsedResult = JSON.parse(contentPart.text); displayProofreadResults(text, parsedResult); } else { throw new Error("Invalid response structure from API."); } } catch (error) { console.error("Error during proofreading:", error); showMessage(`An error occurred: ${error.message}. Please try again.`); } finally { setLoadingState(proofreadBtn, proofreadBtnText, proofreadBtnLoader, false); } }; const displayProofreadResults = (originalText, data) => { proofreadResultContainer.innerHTML = ''; proofreadResultContainer.classList.remove('hidden'); const resultsHtml = `

Proofreading Analysis

Original Text

${originalText}

Corrected Text

${data.correctedText}

Summary of Changes

${data.changes.length > 0 ? data.changes.map(change => `
${change.type}

${change.original}${change.suggestion}

${change.explanation}

`).join('') : '

No errors found!

'}
`; proofreadResultContainer.innerHTML = resultsHtml; proofreadPdfDownloadBtn.classList.remove('hidden'); }; // --- PDF Download Functions --- const downloadPDF = async (elementId, fileName) => { const { jsPDF } = window.jspdf; const pdfOutput = document.getElementById(elementId); if (!pdfOutput) return; const canvas = await html2canvas(pdfOutput, { scale: 2, backgroundColor: '#ffffff' }); const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF({ orientation: 'portrait', unit: 'pt', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const imgProps = pdf.getImageProperties(imgData); const pdfHeight = (imgProps.height * pdfWidth) / imgProps.width; pdf.addImage(imgData, 'PNG', 40, 40, pdfWidth - 80, pdfHeight - 80); pdf.save(fileName); }; // --- Event Listeners --- generateQuizBtn.addEventListener('click', handleQuizGeneration); quizPdfDownloadBtn.addEventListener('click', () => downloadPDF('quizPdfOutput', 'Quiz-Results.pdf')); proofreadBtn.addEventListener('click', handleProofread); proofreadPdfDownloadBtn.addEventListener('click', () => downloadPDF('proofreadPdfOutput', 'Proofreading-Analysis.pdf')); // Initialize view showTab('quizTab'); });
Scroll to Top