(async function () { const res = await fetch('data.json'); const versions = await res.json(); const input = document.getElementById('search'); input.focus(); input.addEventListener('input', (e) => { const query = e.target.value.toLowerCase(); for (const version of versions) { const heading = document.getElementById(version.name); if (version.lib.length == 0 && version.non_lib.length == 0) { heading.hidden = query.length != 0; continue; } const nonLibResults = search(version.non_lib, query); const libResults = search(version.lib, query); const totalResultCount = nonLibResults.length + libResults.length; // so that release notes don't get in the way when ing through results document.body.classList.toggle('hide-release-notes', totalResultCount == 0); let list = document.getElementById(version.name + '-non-lib-list'); if (list) { list.replaceChildren(...renderList(nonLibResults).children); list.hidden = nonLibResults.length == 0; } list = document.getElementById(version.name + '-lib-list'); if (list) { list.replaceChildren(...renderList(libResults).children); list.hidden = libResults.length == 0; document.getElementById(version.name + '-lib-heading').hidden = libResults.length == 0; } heading.hidden = totalResultCount == 0; } }); })(); function search(features, query) { return features.filter((feat) => { if (feat.title.toLowerCase().replaceAll('`', '').includes(query)) { return true; } if (feat.flag && feat.flag.toLowerCase().includes(query)) { return true; } if (query.length > 1) { if (feat.aliases && feat.aliases.some((a) => a.toLowerCase().includes(query))) { return true; } if (feat.items && feat.items.some((i) => i.toLowerCase().includes(query))) { return true; } } return false; }); } function renderList(results) { const ul = document.createElement('ul'); for (const feat of results) { const li = document.createElement('li'); const a = document.createElement('a'); a.textContent = feat.title; a.innerHTML = a.innerHTML.replaceAll(/`(.+?)`/g, (_, x) => `${x}`); if (feat.url) a.href = feat.url; if (feat.flag) a.title = feat.flag; li.appendChild(a); ul.appendChild(li); } return ul; }