Sentence Sleuth

Sentence Sleuth

Analysis Dashboard

0

Words

0

Sentences

0

Readability

0

Grade Level

Detected Issues

No issues found.

Sentence Analysis

Enter text and click analyze.

Weak Words

Words to flag as "weak" (e.g., adverbs, fillers).

Custom Watchlist

Custom words or phrases to flag (e.g., buzzwords).

No sentences detected.

'; } // 7. Save for PDF ss_lastAnalysis = { stats: { wordCount, sentenceCount, readability: fleschScore.toFixed(1), gradeLevel: gradeLevel.toFixed(1) }, issues: allIssues, sentences: analyzedSentences, originalText: text }; } // --- CONFIGURATION FUNCTIONS --- function ss_renderConfigLists() { // Render Weak Words ss_weakWordListEl.innerHTML = ''; if (ss_data.weakWords.length === 0) { ss_weakWordListEl.innerHTML = '

No weak words added.

'; } ss_data.weakWords.forEach(word => { ss_weakWordListEl.innerHTML += `
${ss_escapeHTML(word)}
`; }); // Render Watchlist Words ss_watchlistListEl.innerHTML = ''; if (ss_data.watchlist.length === 0) { ss_watchlistListEl.innerHTML = '

No watchlist words added.

'; } ss_data.watchlist.forEach(word => { ss_watchlistListEl.innerHTML += `
${ss_escapeHTML(word)}
`; }); } window.ss_addWeakWord = function(event) { event.preventDefault(); const word = ss_newWeakWordInput.value.trim().toLowerCase(); if (word && !ss_data.weakWords.includes(word)) { ss_data.weakWords.push(word); ss_renderConfigLists(); ss_newWeakWordInput.value = ''; } } window.ss_deleteWeakWord = function(word) { ss_data.weakWords = ss_data.weakWords.filter(w => w !== word); ss_renderConfigLists(); } window.ss_addWatchlistWord = function(event) { event.preventDefault(); const word = ss_newWatchlistWordInput.value.trim().toLowerCase(); if (word && !ss_data.watchlist.includes(word)) { ss_data.watchlist.push(word); ss_renderConfigLists(); ss_newWatchlistWordInput.value = ''; } } window.ss_deleteWatchlistWord = function(word) { ss_data.watchlist = ss_data.watchlist.filter(w => w !== word); ss_renderConfigLists(); } // --- TAB & NAVIGATION FUNCTIONS --- window.ss_switchTab = function(tabIndex) { ss_currentTabIndex = tabIndex; ss_tabContents.forEach((content, index) => { content.classList.toggle('ss-active', index === tabIndex); }); ss_tabs.forEach((tab, index) => { tab.classList.toggle('ss-active', index === tabIndex); }); ss_updateNavButtons(); } window.ss_navigateTabs = function(direction) { if (direction === 'next' && ss_currentTabIndex < ss_numTabs - 1) { ss_switchTab(ss_currentTabIndex + 1); } else if (direction === 'prev' && ss_currentTabIndex > 0) { ss_switchTab(ss_currentTabIndex - 1); } } function ss_updateNavButtons() { ss_prevBtn.style.visibility = (ss_currentTabIndex === 0) ? 'hidden' : 'visible'; ss_nextBtn.style.visibility = (ss_currentTabIndex === ss_numTabs - 1) ? 'hidden' : 'visible'; } // --- PDF GENERATION --- window.ss_generatePdf = function() { if (typeof jspdf === 'undefined' || typeof jspdf.jsPDF === 'undefined') { alert('Error: PDF generation library (jsPDF) not loaded.'); return; } if (typeof window.jspdf.plugin.autotable === 'undefined') { alert('Error: PDF generation library (jsPDF-AutoTable) not loaded.'); return; } if (!ss_lastAnalysis.originalText || ss_lastAnalysis.originalText.trim().length === 0) { alert("Please analyze some text before downloading a PDF."); return; } try { const { jsPDF } = jspdf; const doc = new jsPDF(); const margin = 15; const docWidth = doc.internal.pageSize.getWidth(); let cursorY = 20; // Title doc.setFont('helvetica', 'bold'); doc.setFontSize(20); doc.setTextColor(varGet('--ss-primary-color', '#0073e6')); doc.text("Sentence Sleuth Analysis Report", 105, cursorY, { align: 'center' }); cursorY += 15; // Section: Key Statistics doc.setFontSize(14); doc.text("Key Statistics", margin, cursorY); cursorY += 8; doc.setFont('helvetica', 'normal'); doc.setFontSize(11); doc.setTextColor(varGet('--ss-text-color', '#333')); const stats = ss_lastAnalysis.stats; const statsText = [ `Word Count: ${stats.wordCount}`, `Sentence Count: ${stats.sentenceCount}`, `Readability Score (Flesch): ${stats.readability}`, `Reading Grade Level: ${stats.gradeLevel}` ]; doc.text(statsText, margin, cursorY); cursorY += (statsText.length * 5) + 10; // Section: Detected Issues doc.setFont('helvetica', 'bold'); doc.setFontSize(14); doc.setTextColor(varGet('--ss-primary-color', '#0073e6')); doc.text("Detected Issues", margin, cursorY); cursorY += 8; if (ss_lastAnalysis.issues.length > 0) { const tableHead = [["Issue Type", "Detected Text", "Full Sentence"]]; const tableBody = ss_lastAnalysis.issues.map(issue => [ issue.type, issue.text, issue.sentence.replace(/\s+/g, ' ').trim() // Clean up sentence ]); doc.autoTable({ head: tableHead, body: tableBody, startY: cursorY, theme: 'striped', headStyles: { fillColor: varGet('--ss-primary-color', '#0073e6'), textColor: varGet('--ss-text-light', '#fff') }, styles: { font: 'helvetica', cellPadding: 2.5, overflow: 'linebreak' }, alternateRowStyles: { fillColor: varGet('--ss-light-primary', '#e6f1fc') }, columnStyles: { 0: { cellWidth: 35 }, 1: { cellWidth: 40 }, 2: { cellWidth: 100 } } }); cursorY = doc.autoTable.previous.finalY + 10; } else { doc.setFont('helvetica', 'normal'); doc.setFontSize(11); doc.text("No issues were found in the text.", margin, cursorY); cursorY += 10; } // Section: Original Text if (cursorY > 240) { doc.addPage(); cursorY = 20; } // Check for page break doc.setFont('helvetica', 'bold'); doc.setFontSize(14); doc.setTextColor(varGet('--ss-primary-color', '#0073e6')); doc.text("Original Text", margin, cursorY); cursorY += 8; doc.setFont('helvetica', 'normal'); doc.setFontSize(10); doc.setTextColor(varGet('--ss-text-color', '#333')); const splitText = doc.splitTextToSize(ss_lastAnalysis.originalText, docWidth - (margin * 2)); doc.text(splitText, margin, cursorY); // --- Save PDF --- doc.save('sentence_sleuth_report.pdf'); } catch (e) { console.error("PDF Generation Error: ", e); alert("An error occurred while generating the PDF."); } } // --- UTILITY FUNCTIONS --- function varGet(varName, fallback = '#000') { try { return getComputedStyle(document.documentElement).getPropertyValue(varName).trim() || fallback; } catch (e) { return fallback; } } function ss_escapeHTML(str) { if (!str) return ''; return str.replace(/[&<>"']/g, function(m) { return { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[m]; }); } function ss_escapeRegExp(string) { return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); } // --- INITIALIZATION --- function ss_initTool() { ss_switchTab(0); ss_renderConfigLists(); // Add USA-relevant sample text ss_textInput.value = "We must leverage our core competencies to achieve synergy. It is very important that this is done. We will circle back next week to utilize all resources. The report was seen by the manager."; // Run analysis on sample text ss_analyzeText(); } ss_initTool(); // Run the tool }); // End of DOMContentLoaded