diff --git a/script.js b/script.js index bdc06f3..d1aeddb 100644 --- a/script.js +++ b/script.js @@ -413,6 +413,29 @@ async function syncClassSwitcher() { renderSemesterTabs(); } +function prepareSearchIndex() { + if (!pdfDatabase || !Array.isArray(pdfDatabase)) return; + + pdfDatabase.forEach(pdf => { + // Create a search string: lowercased concatenation of relevant fields + // Use a safe fallback for missing fields to avoid runtime errors + const searchStr = ( + (pdf.title || '') + ' ' + + (pdf.description || '') + ' ' + + (pdf.category || '') + ' ' + + (pdf.author || '') + ).toLowerCase(); + + // Use Object.defineProperty to make it non-enumerable + // This ensures it is NOT saved to localStorage when we cache pdfDatabase + Object.defineProperty(pdf, '_searchStr', { + value: searchStr, + enumerable: false, + writable: true + }); + }); +} + async function loadPDFDatabase() { if (isMaintenanceActive) return; @@ -451,6 +474,7 @@ async function loadPDFDatabase() { if (shouldUseCache) { pdfDatabase = cachedData; + prepareSearchIndex(); // --- FIX: CALL THIS TO POPULATE UI --- syncClassSwitcher(); renderSemesterTabs(); @@ -474,6 +498,8 @@ async function loadPDFDatabase() { data: pdfDatabase })); + prepareSearchIndex(); + // --- FIX: CALL THIS TO POPULATE UI --- syncClassSwitcher(); renderPDFs(); @@ -915,10 +941,12 @@ 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); + const matchesSearch = pdf._searchStr + ? pdf._searchStr.includes(searchTerm) + : (pdf.title.toLowerCase().includes(searchTerm) || + pdf.description.toLowerCase().includes(searchTerm) || + pdf.category.toLowerCase().includes(searchTerm) || + (pdf.author && pdf.author.toLowerCase().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