PageSourceSearch

https://chrsor.github.io/assets/js/notes-search-i18n.js

js chrsor.github.io collected 2026-10-03 08:47:56 UTC 1,969 bytes, 39 lines download raw bytes

1(function () {
2  "use strict";
3  function init() {
4    const list = document.getElementById("notes-list");
5    const query = document.getElementById("notes-query");
6    const select = document.getElementById("notes-tag");
7    const count = document.getElementById("notes-count");
8    const controls = document.querySelector(".notes-search");
9    if (!list || !query || !select || !count || !controls) return;
10    const clean = value => String(value).normalize("NFKC").toLocaleLowerCase().replace(/\s+/g, " ").trim();
11    const cards = Array.from(list.querySelectorAll(".note-card"));
12    const records = cards.map(card => ({
13      card,
14      text: clean(card.textContent),
15      tags: Array.from(card.querySelectorAll("[data-note-tag]")).map(t => t.textContent.trim())
16    }));
17    const tags = Array.from(new Set(records.flatMap(record => record.tags))).sort((a, b) => a.localeCompare(b));
18    tags.forEach(tag => {
19      const option = document.createElement("option");
20      option.value = tag; option.textContent = tag; select.appendChild(option);
21    });
22    function update() {
23      const words = clean(query.value).split(" ").filter(Boolean);
24      let visible = 0;
25      records.forEach(record => {
26        const match = words.every(word => record.text.includes(word)) && (!select.value || record.tags.includes(select.value));
27        record.card.hidden = !match;
28        if (match) visible += 1;
29      });
30      count.textContent = document.documentElement.lang.split("-")[0] === "de" ? visible + " von " + records.length + " Notizen angezeigt" : visible + " of " + records.length + " notes shown";
31      const empty = document.getElementById("notes-empty");
32      if (empty) empty.hidden = visible !== 0;
33    }
34    query.addEventListener("input", update); select.addEventListener("change", update);
35    controls.hidden = false; update();
36  }
37  if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", init);
38  else init();
39}());

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.