From 011ad3ce2853cc08dc7f110952657e531ff424cc Mon Sep 17 00:00:00 2001 From: dannyhpy Date: Sat, 30 Dec 2023 17:39:20 +0100 Subject: [PATCH] --- index.html | 8 ++++++++ index.js | 15 +++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index bda81cf..2123021 100644 --- a/index.html +++ b/index.html @@ -27,6 +27,14 @@

diff --git a/index.js b/index.js index 60f0b53..156216c 100644 --- a/index.js +++ b/index.js @@ -23,6 +23,9 @@ function buildSearchURL (opts = {}) { const params = new URLSearchParams({ q: opts.query }) + if (opts.category && opts.category !== 'all') { + params.append(`category_${opts.category}`, '') + } const url = `${instanceURL}?${params.toString()}` return url } @@ -31,7 +34,8 @@ function buildSearchURL (opts = {}) { formEl.addEventListener('submit', (event) => { event.preventDefault() location.assign(buildSearchURL({ - query: formEl.query.value + query: formEl.query.value, + category: formEl.category.value })) }) @@ -92,14 +96,13 @@ if (location.search.length > 0) { const searchParams = new URLSearchParams(location.search.slice(1)) if (searchParams.has('q')) { location.assign(buildSearchURL({ - query: searchParams.get('q') + query: searchParams.get('q'), + category: searchParams.get('in') ?? 'all' })) } } +infoEl.textContent = `${data.instances.length} instances` if (data.instances.length > 0) { - infoEl.textContent = `${data.instances.length} instances` -} else { infoEl.classList.add('error') - infoEl.textContent = '0 instances' -} \ No newline at end of file +}