PageSourceSearch

https://putyourlightson.com/src/js/scripts.js?v=2026091601

js putyourlightson.com collected 2026-09-25 21:12:48 UTC 2,357 bytes, 67 lines download raw bytes

1// Initiate lightbox
2const lightbox = GLightbox();
3
4// Search
5const search = document.getElementById('search');
6if (search) {
7    const search = document.getElementById('search');
8    const results = document.getElementById('results');
9
10    const doSearch = function() {
11        let html = '';
12        let query = search.value;
13        if (query && query !== ' ') {
14            let searchResults = [];
15            searchKeywords.forEach(item => {
16                let score = 0;
17                let text = '';
18                let headingText = '<b>' + item.heading + '</b>';
19                let headingIndex = item.heading.toLowerCase().indexOf(query.toLowerCase());
20                if (headingIndex !== -1) {
21                    score = 100 - headingIndex;
22                    text = headingText;
23                } else {
24                    const regexp = new RegExp('(\\S* )?\\S*' + query + '\\S*( \\S*)?', 'i');
25                    const match = item.text.match(regexp);
26                    if (match) {
27                        score = 1;
28                        text = headingText + '<br>' + match[0] + (match[0].endsWith('.') ? '' : '...');
29                    }
30                }
31
32                if (score > 0) {
33                    searchResults.push({
34                        score: score,
35                        id: item.id,
36                        text: text,
37                    });
38                }
39            });
40
41            searchResults.sort((a, b) => b.score - a.score);
42            searchResults = searchResults.slice(0, 10);
43            searchResults.forEach(item => {
44                html += '<a href="#' + item.id + '">'
45                    + item.text.replace(/`/g, '').replace(new RegExp('(' + query + ')', 'gi'), '<span>$1</span>')
46                    + '</a>';
47            });
48        }
49
50        results.innerHTML = html;
51
52        if (html) {
53            results.classList.remove('hidden');
54            results.querySelectorAll('a').forEach(element => {
55                element.addEventListener('click', () => {
56                    results.classList.add('hidden');
57                });
58            });
59        } else {
60            results.classList.add('hidden');
61        }
62    };
63
64    search.addEventListener('keyup', doSearch);
65    search.addEventListener('focus', doSearch);
66    search.addEventListener('search', doSearch);
67}

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.