White Paper Summary Generator
Distill lengthy documents into concise summaries instantly.
Provide the text in the previous step and click 'Generate Summary' to see the result.
Input text is empty. Please provide the white paper content.
'; const stopWords = getStopWords(); // 1. Split text into sentences const sentences = text.match(/[^.!?]+[.!?]+/g) || []; if (sentences.length < sentenceCount) { return text.split('\n').map(p => `${p}
`).join(''); } // 2. Create word frequency map const wordFrequencies = {}; const words = text.toLowerCase().replace(/[^a-zA-Z\s]/g, '').split(/\s+/); words.forEach(word => { if (!stopWords.has(word)) { wordFrequencies[word] = (wordFrequencies[word] || 0) + 1; } }); // 3. Score each sentence const sentenceScores = sentences.map(sentence => { let score = 0; const sentenceWords = sentence.toLowerCase().replace(/[^a-zA-Z\s]/g, '').split(/\s+/); sentenceWords.forEach(word => { if (wordFrequencies[word]) { score += wordFrequencies[word]; } }); return { sentence, score }; }); // 4. Sort sentences by score sentenceScores.sort((a, b) => b.score - a.score); // 5. Select top sentences and re-order them based on original appearance const topSentences = sentenceScores.slice(0, sentenceCount).map(s => s.sentence.trim()); const summarySentences = sentences.filter(s => topSentences.includes(s.trim())); generatedSummary = summarySentences.join(' '); return summarySentences.map(p => `${p}
`).join(''); }; const generateSummaryHandler = () => { const text = whitepaperText.value; if (!text.trim()) { alert("Please paste the white paper text before generating a summary."); switchTab('input'); return; } const summaryHtml = summarizeText(text); summaryOutput.innerHTML = summaryHtml; pdfBtn.disabled = false; switchTab('summary'); }; const generatePDF = () => { if (!generatedSummary) return; const { jsPDF } = window.jspdf; const doc = new jsPDF(); const pageHeight = doc.internal.pageSize.height; const pageWidth = doc.internal.pageSize.width; const margin = 20; const maxLineWidth = pageWidth - margin * 2; let y = margin; // Header doc.setFont('times', 'bold'); doc.setFontSize(24); doc.setTextColor(15, 23, 42); // Slate 900 doc.text('White Paper Summary', pageWidth / 2, y, { align: 'center' }); y += 15; // Sub-header doc.setFont('times', 'normal'); doc.setFontSize(12); doc.setTextColor(71, 85, 105); // Slate 500 doc.text('This document provides a condensed summary of the key points from the source material.', pageWidth / 2, y, { align: 'center'}); y += 15; // Line separator doc.setDrawColor(203, 213, 225); // Slate 300 doc.setLineWidth(0.5); doc.line(margin, y, pageWidth - margin, y); y += 15; // Body text doc.setFont('times', 'normal'); doc.setFontSize(12); doc.setTextColor(30, 41, 59); // Slate 700 doc.setLineHeightFactor(1.5); const lines = doc.splitTextToSize(generatedSummary, maxLineWidth); doc.text(lines, margin, y); // Footer const footerY = pageHeight - 15; doc.line(margin, footerY, pageWidth - margin, footerY); doc.setFontSize(9); doc.setTextColor(148, 163, 184); // Slate 400 const today = new Date().toLocaleDateString('en-US'); doc.text(`Summary Generated on ${today}`, margin, footerY + 5); doc.save('White_Paper_Summary.pdf'); }; const switchTab = (tabName) => { if (!tabs.includes(tabName)) return; currentTab = tabName; Object.values(tabContent).forEach(content => content.classList.add('hidden')); tabContent[tabName].classList.remove('hidden'); Object.values(tabButtons).forEach(button => button.classList.remove('active')); tabButtons[tabName].classList.add('active'); updateNavButtons(); }; const updateNavButtons = () => { const currentIndex = tabs.indexOf(currentTab); prevBtn.disabled = currentIndex === 0; nextBtn.disabled = currentIndex === tabs.length - 1; }; const navigateTabs = (direction) => { const currentIndex = tabs.indexOf(currentTab); let newIndex = direction === 'next' ? Math.min(currentIndex + 1, tabs.length - 1) : Math.max(currentIndex - 1, 0); switchTab(tabs[newIndex]); }; generateBtn.addEventListener('click', generateSummaryHandler); pdfBtn.addEventListener('click', generatePDF); window.app = { switchTab, navigateTabs, }; updateNavButtons(); });