diff --git a/script.js b/script.js index bdc06f3..ebe9dcb 100644 --- a/script.js +++ b/script.js @@ -788,7 +788,18 @@ function getEmbeddableUrl(url) { return `https://docs.google.com/gview?embedded=true&url=${encodeURIComponent(url)}`; } -async function viewPDF(pdf, pushToHistory = true) { +async function viewPDF(pdfOrId, pushToHistory = true) { + // Optimization: Support passing ID string to avoid large HTML payload + const pdf = (typeof pdfOrId === 'string') + ? pdfDatabase.find(p => p.id === pdfOrId) + : pdfOrId; + + if (!pdf) { + console.error('PDF not found:', pdfOrId); + showToast('Error: PDF data not found.', 'error'); + return; + } + const originalPdfPath = pdf.pdfUrl; logInteraction('view_pdf', pdf.title, pdf.id); @@ -1020,7 +1031,8 @@ function createPDFCard(pdf, favoritesList, index = 0, highlightRegex = null) { return safeText.replace(highlightRegex, '$1'); }; - const safePdfString = JSON.stringify(pdf).replace(/"/g, '"'); + // Optimization: Removed expensive JSON.stringify(pdf) here. + // Instead, we pass the ID to viewPDF() which looks it up in O(1) or O(n). // --- NEW: Calculate Stagger Delay --- // Cap at 1s (20 items) so the list doesn't feel unresponsive @@ -1037,7 +1049,7 @@ function createPDFCard(pdf, favoritesList, index = 0, highlightRegex = null) {

${highlightText(pdf.description)}

-