PageSourceSearch

https://www.tibz.blog/js/search.js

js tibz.blog collected 2026-10-05 03:40:46 UTC 2,244 bytes, 88 lines download raw bytes

1var resultsContainer = document.getElementById("list_results");
2var maxResults = parseInt(resultsContainer.dataset.maxResults, 10) || 5;
3
4var archive_results = {};
5
6function runSearch(q) {
7	resultsContainer.innerHTML = "";
8
9	if (q.length > 0) {
10		var resultsFound = false;
11		var resultCount = 0;
12
13		for (var i = 0; i < archive_results.items.length; i++) {
14			var item = archive_results.items[i];
15			var title_lower = item.title.toLowerCase();
16			var text_lower = item.content_text.toLowerCase();
17
18			if (title_lower.includes(q) || text_lower.includes(q)) {
19				var p_node = document.createElement("p");
20				var link_node = document.createElement("a");
21				var d = Date.parse(item.date_published);
22				var date_s = new Date(d).toLocaleDateString().substr(0, 10);
23				var date_node = document.createTextNode(date_s);
24				link_node.appendChild(date_node);
25				link_node.href = item.url;
26				var title_node = null;
27
28				if (item.title.length > 0) {
29					title_node = document.createElement("span");
30					title_node.innerHTML = ": <b>" + item.title + "</b>";
31				}
32
33				var s = item.content_text;
34				if (s.length > 200) {
35					s = s.substr(0, 200) + "...";
36				}
37
38				var text_node = document.createElement("span");
39				text_node.innerHTML = ": " + s;
40
41				p_node.appendChild(link_node);
42
43				if (title_node != null) {
44					p_node.appendChild(title_node);
45				}
46
47				p_node.appendChild(text_node);
48				resultsContainer.appendChild(p_node);
49
50				resultCount++;
51				resultsFound = true;
52
53				if (resultCount >= maxResults) {
54					break;
55				}
56			}
57		}
58
59		resultsContainer.style.display = resultsFound ? "block" : "none";
60	} else {
61		resultsContainer.style.display = "none";
62	}
63}
64
65function submitSearch(q) {
66	runSearch(q);
67
68	const url = new URL(window.location.href);
69	url.searchParams.set("q", q);
70	history.pushState({}, "", url);
71}
72
73document.addEventListener("DOMContentLoaded", function () {
74	fetch("/archive/index.json")
75		.then(response => response.json())
76		.then(data => {
77			archive_results = data;
78
79			const url = window.location.href;
80			const params = new URLSearchParams(new URL(url).search);
81			const q = params.get("q");
82
83			if (q && q.length > 0) {
84				document.getElementById("input_search").value = q;
85				runSearch(q);
86			}
87		});
88});

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.