diff --git a/script.js b/script.js index bdc06f3..faf76e0 100644 --- a/script.js +++ b/script.js @@ -451,6 +451,7 @@ async function loadPDFDatabase() { if (shouldUseCache) { pdfDatabase = cachedData; + prepareSearchIndex(pdfDatabase); // --- FIX: CALL THIS TO POPULATE UI --- syncClassSwitcher(); renderSemesterTabs(); @@ -474,6 +475,8 @@ async function loadPDFDatabase() { data: pdfDatabase })); + prepareSearchIndex(pdfDatabase); + // --- FIX: CALL THIS TO POPULATE UI --- syncClassSwitcher(); renderPDFs(); @@ -485,6 +488,26 @@ async function loadPDFDatabase() { } } +function prepareSearchIndex(pdfs) { + if (!pdfs) return; + pdfs.forEach(pdf => { + // Concatenate fields for search optimization + // Use || "" to handle potential undefined fields gracefully + const searchStr = ( + (pdf.title || "") + " " + + (pdf.description || "") + " " + + (pdf.category || "") + " " + + (pdf.author || "") + ).toLowerCase(); + + Object.defineProperty(pdf, '_searchStr', { + value: searchStr, + enumerable: false, // Don't show in loops or JSON.stringify + writable: true + }); + }); +} + function hidePreloader() { if (preloader) { preloader.classList.add('hidden'); @@ -915,10 +938,8 @@ function renderPDFs() { matchesCategory = currentCategory === 'all' || pdf.category === currentCategory; } - const matchesSearch = pdf.title.toLowerCase().includes(searchTerm) || - pdf.description.toLowerCase().includes(searchTerm) || - pdf.category.toLowerCase().includes(searchTerm) || - pdf.author.toLowerCase().includes(searchTerm); + // OPTIMIZED: Use pre-computed search string + const matchesSearch = (pdf._searchStr || "").includes(searchTerm); // Update return statement to include matchesClass return matchesSemester && matchesClass && matchesCategory && matchesSearch; diff --git a/verification.png b/verification.png deleted file mode 100644 index 77025f3..0000000 Binary files a/verification.png and /dev/null differ