PageSourceSearch

https://111586.xyz/js/archive.js

js 111586.xyz collected 2026-10-09 04:34:06 UTC 4,197 bytes, 143 lines download raw bytes

1/*
2Credits: this script is shamelessly borrowed from
3https://github.com/kitian616/jekyll-TeXt-theme
4*/
5(function() {
6  function queryString() {
7    // This function is anonymous, is executed immediately and
8    // the return value is assigned to QueryString!
9    var i = 0, queryObj = {}, pair;
10    var queryStr = window.location.search.substring(1);
11    var queryArr = queryStr.split('&');
12    for (i = 0; i < queryArr.length; i++) {
13      pair = queryArr[i].split('=');
14      // If first entry with this name
15      if (typeof queryObj[pair[0]] === 'undefined') {
16        queryObj[pair[0]] = pair[1];
17        // If second entry with this name
18      } else if (typeof queryObj[pair[0]] === 'string') {
19        queryObj[pair[0]] = [queryObj[pair[0]], pair[1]];
20        // If third or later entry with this name
21      } else {
22        queryObj[pair[0]].push(pair[1]);
23      }
24    }
25    return queryObj;
26  }
27
28  var setUrlQuery = (function() {
29    var baseUrl =  window.location.href.split('?')[0];
30    return function(query) {
31      if (typeof query === 'string') {
32        window.history.replaceState(null, '', baseUrl + query);
33      } else {
34        window.history.replaceState(null, '', baseUrl);
35      }
36    };
37  })();
38
39  $(document).ready(function() {
40    var $tags = $('.js-tags');
41    var $articleTags = $tags.find('.tag-button');
42    var $tagShowAll = $tags.find('.tag-button--all');
43    var $result = $('.js-result');
44    var $sections = $result.find('section');
45    var sectionArticles = []
46    var $lastFocusButton = null;
47    var sectionTopArticleIndex = [];
48    var hasInit = false;
49
50    $sections.each(function() {
51      sectionArticles.push($(this).find('.item'));
52    });
53
54    function init() {
55      var i, index = 0;
56      for (i = 0; i < $sections.length; i++) {
57        sectionTopArticleIndex.push(index);
58        index += $sections.eq(i).find('.item').length;
59      }
60      sectionTopArticleIndex.push(index);
61    }
62
63    function searchButtonsByTag(_tag/*raw tag*/) {
64      if (!_tag) {
65        return $tagShowAll;
66      }
67      var _buttons = $articleTags.filter('[data-encode="' + _tag + '"]');
68      if (_buttons.length === 0) {
69        return $tagShowAll;
70      }
71      return _buttons;
72    }
73
74    function buttonFocus(target) {
75      if (target) {
76        target.addClass('focus');
77        $lastFocusButton && !$lastFocusButton.is(target) && $lastFocusButton.removeClass('focus');
78        $lastFocusButton = target;
79      }
80    }
81
82    function tagSelect (tag/*raw tag*/, target) {
83      var result = {}, $articles;
84      var i, j, k, _tag;
85
86      for (i = 0; i < sectionArticles.length; i++) {
87        $articles = sectionArticles[i];
88        for (j = 0; j < $articles.length; j++) {
89          if (tag === '' || tag === undefined) {
90            result[i] || (result[i] = {});
91            result[i][j] = true;
92          } else {
93            var tags = $articles.eq(j).data('tags').split(',');
94            for (k = 0; k < tags.length; k++) {
95              if (tags[k] === tag) {
96                result[i] || (result[i] = {});
97                result[i][j] = true; break;
98              }
99            }
100          }
101        }
102      }
103
104      for (i = 0; i < sectionArticles.length; i++) {
105        result[i] && $sections.eq(i).removeClass('d-none');
106        result[i] || $sections.eq(i).addClass('d-none');
107        for (j = 0; j < sectionArticles[i].length; j++) {
108          if (result[i] && result[i][j]) {
109            sectionArticles[i].eq(j).removeClass('d-none');
110          } else {
111            sectionArticles[i].eq(j).addClass('d-none');
112          }
113        }
114      }
115
116      hasInit || ($result.removeClass('d-none'), hasInit = true);
117
118
119      if (target) {
120        buttonFocus(target);
121        _tag = target.attr('data-encode');
122        if (_tag === '' || typeof _tag !== 'string') {
123          setUrlQuery();
124        } else {
125          setUrlQuery('?tag=' + _tag);
126        }
127      } else {
128        buttonFocus(searchButtonsByTag(tag));
129      }
130    }
131
132    var query = queryString(), 
133        _tag = query.tag;
134
135    init(); 
136    tagSelect(_tag);
137
138    $tags.on('click', 'a', function() {   /* only change */
139      tagSelect($(this).data('encode'), $(this));
140    });
141
142  });
143})();

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.