From 4b3779baa7a2d0761f604757a6c7d4594c0f5548 Mon Sep 17 00:00:00 2001 From: kisfenyo Date: Wed, 14 Jan 2026 20:48:14 +0100 Subject: [PATCH] we'll see --- glance-system/glance-kisfenyo.yaml | 96 +++++++++++++++--------------- 1 file changed, 47 insertions(+), 49 deletions(-) diff --git a/glance-system/glance-kisfenyo.yaml b/glance-system/glance-kisfenyo.yaml index 5bf9cd1..11365d4 100644 --- a/glance-system/glance-kisfenyo.yaml +++ b/glance-system/glance-kisfenyo.yaml @@ -118,59 +118,55 @@ data: let activeIndex = 0; let lastQuery = ''; - function normalize(s) { - return (s || '').toLowerCase().replace(/\s+/g, ' ').trim(); + const BOOKMARKS_INDEX_URL = '/assets/bookmarks.json'; + + let indexLoaded = false; + let indexLoading = null; + + function indexLinksFromDom() { + const anchors = document.querySelectorAll('.widget.widget-type-bookmarks a.bookmarks-link[href]'); + indexed = Array.from(anchors).map(a => ({ + title: (a.textContent || '').trim(), + url: a.href, + meta: '' + })); } - function indexLinks() { - const BOOKMARKS_INDEX_URL = '/assets/bookmarks.json'; + function loadBookmarksIndex() { + if (indexLoaded) return Promise.resolve(); + if (indexLoading) return indexLoading; - let indexLoaded = false; - let indexLoading = null; + indexLoading = fetch(BOOKMARKS_INDEX_URL, { cache: 'no-store' }) + .then(res => { + if (!res.ok) throw new Error(`HTTP ${res.status}`); + return res.json(); + }) + .then(data => { + indexed = data.map(x => ({ + title: x.title, + url: x.url, + meta: [x.page, x.widget, x.group].filter(Boolean).join(' • ') + })); + indexLoaded = true; + }) + .catch(e => { + console.warn('Could not load bookmarks index, falling back to DOM only:', e); + indexLinksFromDom(); + indexLoaded = true; + }); - function indexLinksFromDom() { - // fallback: current page bookmarks only - const anchors = document.querySelectorAll('.widget.widget-type-bookmarks a.bookmarks-link[href]'); - indexed = Array.from(anchors).map(a => ({ - title: (a.textContent || '').trim(), - url: a.href, - meta: '' - })); - } + return indexLoading; + } - async function loadBookmarksIndex() { - if (indexLoaded) return; - if (indexLoading) return indexLoading; + // Load ASAP (works even if DOMContentLoaded already happened) + if (document.readyState === 'loading') { + document.addEventListener('DOMContentLoaded', () => loadBookmarksIndex()); + } else { + loadBookmarksIndex(); + } - indexLoading = (async () => { - try { - const res = await fetch(BOOKMARKS_INDEX_URL, { cache: 'no-store' }); - if (!res.ok) throw new Error(`HTTP ${res.status}`); - const data = await res.json(); - - indexed = data.map(x => ({ - title: x.title, - url: x.url, - meta: [x.page, x.widget, x.group].filter(Boolean).join(' • ') - })); - - indexLoaded = true; - } catch (e) { - console.warn('Could not load bookmarks index, falling back to DOM only:', e); - indexLinksFromDom(); - indexLoaded = true; - } - })(); - - return indexLoading; - } - - // Load ASAP (works even if DOMContentLoaded already happened) - if (document.readyState === 'loading') { - document.addEventListener('DOMContentLoaded', loadBookmarksIndex); - } else { - loadBookmarksIndex(); - } + function normalize(s) { + return (s || '').toLowerCase().replace(/\s+/g, ' ').trim(); } function score(item, q) { @@ -228,8 +224,10 @@ data: list().innerHTML = `
Loading…
`; // then render once index is available - loadBookmarksIndex().then(() => render(normalize(input().value))); - input().focus(); + loadBookmarksIndex().then(() => { + render(normalize(input().value)); + input().focus(); + }); function onInput() { lastQuery = input().value;