document.addEventListener('DOMContentLoaded', function () { ////console.log('FuzzySearch original script loaded'); const input = document.getElementById('fuzzysearch-input'); const resultsList = document.getElementById('fuzzysearch-results'); if (!input || !resultsList) { console.error('Fuzzy search elements not found!'); return; } let fuse, currentIndex = -1; fetch(DOKU_BASE + 'lib/exe/ajax.php?call=fuzzysearch_pages', { method: 'GET', credentials: 'same-origin' }) .then(response => { if (!response.ok) throw new Error('Fetch failed'); return response.json(); }) .then(data => { fuse = new Fuse(data, { keys: ['title'], threshold: 0.4, includeScore: true }); input.addEventListener('input', function () { const query = this.value.trim(); resultsList.innerHTML = ''; currentIndex = -1; if (query.length === 0) return; const results = fuse.search(query); results.forEach((result, index) => { const page = result.item; const li = document.createElement('li'); li.innerHTML = `${page.title}`; li.dataset.index = index; resultsList.appendChild(li); }); if (results.length === 0) { resultsList.innerHTML = '