Passive Voice Checker

Passive Voice Checker

Improve clarity and impact by identifying and revising passive sentences.

Please enter some text to analyze.

'; elements.resultsSummary.textContent = ''; elements.resultsSection.classList.remove('hidden'); return; } // Split text into sentences. This regex handles basic cases. const sentences = text.match(/[^.!?]+[.!?]+/g) || [text]; passiveSentences = []; let outputHtml = ''; sentences.forEach(sentence => { const trimmedSentence = sentence.trim(); if (isPassive(trimmedSentence)) { passiveSentences.push(trimmedSentence); outputHtml += `${sentence}`; } else { outputHtml += sentence; } }); elements.resultsContainer.innerHTML = outputHtml.replace(/\n/g, '
'); elements.resultsSummary.textContent = `Found ${passiveSentences.length} potential passive voice sentence(s).`; elements.resultsSection.classList.remove('hidden'); }; const handleDownloadPdf = () => { const { jsPDF } = window.jspdf; if (!jsPDF) { console.error("jsPDF is not loaded."); return; } const doc = new jsPDF({ orientation: 'portrait', unit: 'in', format: 'letter' }); const originalText = elements.textInput.value; const margin = 0.75; const pageWidth = doc.internal.pageSize.getWidth(); const usableWidth = pageWidth - (margin * 2); let currentY = 0; // PDF Header doc.setFillColor('#f0fdf4'); // green-50 doc.rect(0, 0, pageWidth, 1.5, 'F'); doc.setFont('helvetica', 'bold'); doc.setFontSize(22); doc.setTextColor('#166534'); // green-800 doc.text('Writing Analysis Report', margin, 0.9); doc.setFontSize(11); doc.setTextColor('#15803d'); // green-700 doc.text(`Generated on: ${new Date().toLocaleDateString('en-US')}`, margin, 1.2); currentY = 1.9; // Original Text Section doc.setFont('helvetica', 'bold'); doc.setFontSize(12); doc.setTextColor('#1f2937'); // gray-800 doc.text('ORIGINAL TEXT', margin, currentY); doc.setDrawColor('#d1d5db'); doc.line(margin, currentY + 0.05, pageWidth - margin, currentY + 0.05); currentY += 0.3; doc.setFont('times', 'normal'); doc.setFontSize(11); doc.setTextColor('#374151'); // gray-700 const textLines = doc.splitTextToSize(originalText, usableWidth); doc.text(textLines, margin, currentY); currentY += (textLines.length * 0.2) + 0.3; // Passive Voice Analysis Section if (currentY > 8) { doc.addPage(); currentY = margin; } doc.setFont('helvetica', 'bold'); doc.setFontSize(12); doc.setTextColor('#1f2937'); // gray-800 doc.text(`PASSIVE VOICE ANALYSIS (${passiveSentences.length} FOUND)`, margin, currentY); doc.line(margin, currentY + 0.05, pageWidth - margin, currentY + 0.05); currentY += 0.3; if (passiveSentences.length > 0) { doc.setFont('helvetica', 'normal'); doc.setFontSize(10); passiveSentences.forEach(sentence => { if (currentY > 10.2) { doc.addPage(); currentY = margin; } doc.setFillColor('#fefce8'); // yellow-50 const sentenceLines = doc.splitTextToSize(`• ${sentence}`, usableWidth - 0.1); const rectHeight = (sentenceLines.length * 0.18) + 0.1; doc.roundedRect(margin - 0.05, currentY - 0.13, usableWidth + 0.1, rectHeight, 0.05, 0.05, 'F'); doc.setTextColor('#422006'); // amber-900 doc.text(sentenceLines, margin + 0.1, currentY); currentY += rectHeight + 0.1; }); } else { doc.setFont('helvetica', 'italic'); doc.setFontSize(10); doc.setTextColor('#6b7280'); // gray-500 doc.text("No passive voice sentences were detected.", margin, currentY); } doc.save('Writing-Analysis-Report.pdf'); }; // --- Event Listeners --- elements.checkTextBtn.addEventListener('click', analyzeText); elements.downloadPdfBtn.addEventListener('click', handleDownloadPdf); });
Scroll to Top