summaryrefslogtreecommitdiff
path: root/script.js
blob: aa080837ca20cea9c5d4b0a1ac651d158b420b18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
(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 [key, data] of Object.entries(versions)) {
			const heading = document.getElementById(key);

			if (data.features == undefined) {
				heading.hidden = query.length != 0;
				continue;
			}
			const results = Object.values(data.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;
				}
			);

			// so that release notes don't get in the way when <Tab>ing through results
			document.body.classList.toggle('hide-release-notes', results.length == 0);

			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) => `<code>${x}</code>`);
				a.href = feat.url;
				if (feat.flag)
					a.title = feat.flag;
				li.appendChild(a);
				ul.appendChild(li);
			}
			const list = document.getElementById(key + '-list');
			list.replaceChildren(...ul.children);
			list.hidden = results.length == 0;
			heading.hidden = results.length == 0;
		}
	});
})();