PageSourceSearch

https://zxy.me/template/default/js/script.js?v=20260826

js zxy.me collected 2026-10-08 05:52:43 UTC 12,692 bytes, 322 lines download raw bytes

1
2//输入框获取焦点
3window.onload = function () {
4    var text = document.getElementById('search-text');
5    text.focus();
6
7}
8
9const searchInput = document.getElementById('search-text');
10const wordList = document.getElementById('word').getElementsByTagName('li');
11let selectedWordIndex = -1;
12let ignoreKeyEvents = false; // 新增标志用于判断是否忽略键盘事件
13
14// 监听键盘事件
15searchInput.addEventListener('keydown', function (event) {
16    switch (event.key) {
17        case 'ArrowUp':
18            event.preventDefault();
19            selectPreviousWord();
20            fillInputWithSelectedWord();
21            break;
22        case 'ArrowDown':
23            event.preventDefault();
24            selectNextWord();
25            fillInputWithSelectedWord();
26            break;
27        case 'Enter':
28            // 选中联想项时回车:本站链接直接打开,网页词用当前引擎搜索
29            if (selectedWordIndex >= 0 && wordList[selectedWordIndex]) {
30                event.preventDefault();
31                chooseSugItem(wordList[selectedWordIndex]);
32            }
33            break;
34        default:
35            ignoreKeyEvents = false; // 其他键盘事件恢复正常
36            break;
37    }
38});
39
40// 选中上一个选项(循环)
41function selectPreviousWord() {
42    if (wordList.length === 0) return;
43    if (selectedWordIndex >= 0) {
44        wordList[selectedWordIndex].classList.remove('selected');
45    }
46    selectedWordIndex = (selectedWordIndex - 1 + wordList.length) % wordList.length;
47    wordList[selectedWordIndex].classList.add('selected');
48}
49
50// 选中下一个选项(循环)
51function selectNextWord() {
52    if (wordList.length === 0) return;
53    if (selectedWordIndex >= 0) {
54        wordList[selectedWordIndex].classList.remove('selected');
55    }
56    selectedWordIndex = (selectedWordIndex + 1) % wordList.length;
57    wordList[selectedWordIndex].classList.add('selected');
58}
59
60// 将选中的选项填入输入框
61function fillInputWithSelectedWord() {
62    if (selectedWordIndex !== -1) {
63        searchInput.value = wordList[selectedWordIndex].innerText;
64        ignoreKeyEvents = true; // 标记忽略键盘事件
65    }
66}
67
68// 统一处理联想项选中(点击 / 键盘回车):本站链接直接打开,网页词用当前引擎搜索
69function chooseSugItem(li) {
70    if (!li) return;
71    var type = li.getAttribute('data-type');
72    if (type === 'site') {
73        var href = li.getAttribute('data-href');
74        if (href) window.open(href, '_blank');
75    } else {
76        var word = li.getAttribute('data-text') || li.textContent;
77        $('#search-text').val(word);
78        $('.submit').trigger('click'); // 触发搜索事件
79    }
80    $('#word').empty();
81    $('#word').hide();
82    selectedWordIndex = -1;
83}
84
85//关键词sug + 站内搜索
86$(function () {
87    var sugSeq = 0; // 请求序号,防止异步联想乱序覆盖
88
89    // 获取本站卡片匹配({text, href, type:'site'})
90    function getSiteMatches(keyword) {
91        keyword = (keyword || '').trim().toLowerCase();
92        if (!keyword) return [];
93        var items = [];
94        $('.mylist a[href][title]').each(function () {
95            var name = $(this).attr('title') || '';
96            var href = $(this).attr('href') || '';
97            if (name && href && name.toLowerCase().indexOf(keyword) !== -1) {
98                items.push({ text: name, href: href, type: 'site' });
99            }
100        });
101        return items.slice(0, 5);
102    }
103
104    // 追加一条联想项(本站链接 type:'site' / 网页词 type:'web')
105    function appendSugItem(item) {
106        if (!item || !item.text) return;
107
108        var li = document.createElement('li');
109
110        if (item.type === 'site') {
111            li.className = 'sug-site';
112
113            var icon = document.createElement('span');
114            icon.className = 'sug-icon';
115            icon.innerHTML = '<svg viewBox="0 0 1024 1024" width="14" height="14"><path d="M909.6 854.5L649.5 594.4C690.9 542 714 475.8 714 405.1 714 217.7 562.3 66 375 66S36 217.7 36 405.1 187.7 744.1 375 744.1c70.7 0 136.9-23.1 189.3-64.4l260.1 260.1c9.2 9.2 24.1 9.2 33.3 0l28.3-28.3c9.2-9.2 9.2-24.1-.1-33.3zM375 666c-143.9 0-261-117.1-261-261s117.1-261 261-261 261 117.1 261 261-117.1 261-261 261z"/></svg>';
116            li.appendChild(icon);
117
118            li.setAttribute('data-href', item.href || '');
119        }
120
121        // 主文本
122        li.appendChild(document.createTextNode(item.text));
123
124        if (item.type === 'site') {
125            var badge = document.createElement('span');
126            badge.className = 'sug-badge-inner';
127            badge.textContent = '站内';
128            li.appendChild(badge);
129        }
130
131        li.setAttribute('data-type', item.type);
132        li.setAttribute('data-text', item.text);
133
134        $('#word').append(li);
135    }
136
137    // 联想主流程:先显示本站匹配链接(同步),再追加百度联想词(异步)
138    function runSuggest(keyword) {
139        $('#word').empty();
140        selectedWordIndex = -1;
141        var seq = ++sugSeq;
142        // 1. 本站匹配链接
143        getSiteMatches(keyword).forEach(function (item) {
144            appendSugItem(item);
145        });
146        // 2. 百度联想词
147        $.ajax({
148            url: 'https://suggestion.baidu.com/su?wd=' + encodeURIComponent(keyword),
149            dataType: 'jsonp',
150            jsonp: 'cb',
151            success: function (data) {
152                if (seq !== sugSeq) return; // 结果已过期,丢弃
153                var list = data.s || [];
154                list.slice(0, 8).forEach(function (word) {
155                    var dup = false;
156                    $('#word li').each(function () {
157                        if ($(this).attr('data-text') === word) dup = true;
158                    });
159                    if (!dup) appendSugItem({ text: word, type: 'web' });
160                });
161                if ($('#word li').length) {
162                    $('#word').show();
163                } else {
164                    $('#word').empty();
165                    $('#word').hide();
166                }
167                selectedWordIndex = -1;
168            },
169            error: function () {
170                if (seq !== sugSeq) return;
171                if (!$('#word li').length) {
172                    $('#word').empty();
173                    $('#word').hide();
174                }
175            }
176        });
177        if ($('#word li').length) $('#word').show();
178    }
179
180    //当键盘键被松开时发送Ajax获取数据
181    $('#search-text').on('keyup', function () {
182        if (!ignoreKeyEvents) { // 只有在标志为false时才执行
183            var keywords = $(this).val();
184            if (keywords == '') { $('#word').hide(); return; }
185            runSuggest(keywords);
186        }
187    });
188    //点击联想项:本站链接直接打开,网页词复制给搜索框并搜索
189    $(document).on('click', '#word li', function () {
190        chooseSugItem(this);
191    })
192    $(document).on('click', '.container,.banner-video,nav', function () {
193        $('#word').empty();
194        $('#word').hide();
195    })
196})
197
198
199
200$(function () {
201    $('.type-right').click(function (e) {
202        $('#type-left').toggleClass('showListType');
203        e.stopPropagation();  //阻止冒泡
204    });
205
206    $(document).click(function (e) {
207        var con = $('.type-left');
208        if (!con.is(e.target)) {
209            con.toggleClass('showListType', false);
210        }
211    });
212    $(document).click(function (e) {
213        var con = $('.collapse');
214        if (!con.is(e.target)) {
215            con.toggleClass('show', false);
216        }
217    });
218    $('.type-left ul li').click(function () {
219        $(this).addClass('active').siblings('li').removeClass('active');
220        $('.type-left').toggleClass('showListType');
221        var lylme_tag = '#' + $(this).attr("data-lylme");
222        $('html,body').animate({ scrollTop: $(lylme_tag).offset().top }, 500);
223
224    })
225})
226
227//点击空白处关闭导航
228
229//显示日期和时间
230function show() {
231    var date = new Date();
232    var y = date.getFullYear();     //获取年份  
233    var m = date.getMonth() + 1;   //获取月份  返回0-11  
234    var d = date.getDate(); // 获取日  
235    var w = date.getDay();   //获取星期几  返回0-6   (0=星期天) 
236    var ww = ' 星期' + '日一二三四五六'.charAt(new Date().getDay());//星期几
237    var format = [
238        ("0" + date.getHours()).substr(-2), ("0" + date.getMinutes()).substr(-2)
239    ].join(":");
240
241    document.getElementById("show_date").innerHTML = y + "年" + m + "月" + d + "日 " + ww;
242    document.getElementById("show_time").innerHTML = format;
243    return show;
244}
245setInterval(show(), 1000);
246
247
248!
249    function () {
250        function g() {
251            h(), i(), j(), k()
252        }
253        function h() {
254            d.checked = s()
255        }
256        function i() {
257            var a = document.querySelector('input[name="type"][value="' + p() + '"]');
258            a && (a.checked = !0, l(a))
259        }
260        function j() {
261            v(u())
262        }
263        function k() {
264            w(t())
265        }
266        function l(a) {
267            for (var b = 0; b < e.length; b++) e[b].classList.remove("s-current");
268            a.parentNode.parentNode.parentNode.classList.add("s-current")
269        }
270        function m(a, b) {
271            window.localStorage.setItem("superSearch" + a, b)
272        }
273        function n(a) {
274            return window.localStorage.getItem("superSearch" + a)
275        }
276        function o(a) {
277            f = a.target, v(u()), w(a.target.value), m("type", a.target.value), c.focus(), l(a.target)
278        }
279        function p() {
280            var b = n("type");
281            return b || a[0].value
282        }
283        function q(a) {
284            m("newWindow", a.target.checked ? 1 : -1), x(a.target.checked)
285        }
286        function r(a) {
287            return a.preventDefault(), "" == c.value ? (c.focus(), !1) : (w(t() + c.value), x(s()), s() ? window.open(b.action, +new Date) : location.href = b.action, void 0)
288        }
289        function s() {
290            var a = n("newWindow");
291            return a ? 1 == a : !0
292        }
293        function t() {
294            return document.querySelector('input[name="type"]:checked').value
295        }
296        function u() {
297            return document.querySelector('input[name="type"]:checked').getAttribute("data-placeholder")
298        }
299        function v(a) {
300            c.setAttribute("placeholder", a);
301        }
302        function w(a) {
303            b.action = a
304        }
305        function x(a) {
306            a ? b.target = "_blank" : b.removeAttribute("target")
307        }
308        var y, a = document.querySelectorAll('input[name="type"]'),
309            b = document.querySelector("#super-search-fm"),
310            c = document.querySelector("#search-text"),
311            c = document.querySelector("#search-text"),
312            d = document.querySelector("#set-search-blank"),
313            e = document.querySelectorAll(".search-group"),
314            f = a[0];
315        for (g(), y = 0; y < a.length; y++) a[y].addEventListener("change", o);
316        d.addEventListener("change", q), b.addEventListener("submit", r)
317
318    }();
319
320
321//返回顶部
322(function (a) { a.fn.scrollToTop = function (c) { var d = { speed: 8
32200 }; c && a.extend(d, { speed: c }); return this.each(function () { var b = a(this); a(window).scroll(function () { 100 < a(this).scrollTop() ? b.fadeIn() : b.fadeOut() }); b.click(function (b) { b.preventDefault(); a("body, html").animate({ scrollTop: 0 }, d.speed) }) }) } })(jQuery); $(function () { ahtml = '<a href="javascript:void(0)" id="toTop" style="display:none;position:fixed;bottom:66px;right:10px;width:48px;height:48px;background-image:url(\'data:image/svg+xml;base64,PHN2ZyB0PSIxNjU0OTM5MTkxNTY0IiBjbGFzcz0iaWNvbiIgdmlld0JveD0iMCAwIDEwMjQgMTAyNCIgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHAtaWQ9IjEyMTgiIHdpZHRoPSI0OCIgaGVpZ2h0PSI0OCI+PHBhdGggZD0iTTUxMyAxMDMuN2MtMjI2LjEgMC00MDkuNCAxODMuMy00MDkuNCA0MDkuNFMyODYuOSA5MjIuNiA1MTMgOTIyLjZzNDA5LjQtMTgzLjMgNDA5LjQtNDA5LjRTNzM5LjEgMTAzLjcgNTEzIDEwMy43eiBtMTUzLjUgMzY0LjdjLTUuMiA1LjMtMTIuMSA3LjktMTkgNy45cy0xMy44LTIuNi0xOS03LjlMNTQ1LjEgMzg1YzAgMC40IDAuMSAwLjcgMC4xIDEuMVY3MDVjMCAxMS4xLTUuNyAyMC45LTE0LjQgMjYuNi00LjcgNC4yLTEwLjkgNi43LTE3LjcgNi43LTYuOCAwLTEzLTIuNS0xNy43LTYuNy04LjctNS43LTE0LjQtMTUuNS0xNC40LTI2LjZWMzg2LjFjMC0wLjQgMC0wLjcgMC4xLTEuMWwtODMuNCA4My40Yy0xMC41IDEwLjUtMjcuNSAxMC41LTM4IDBzLTEwLjUtMjcuNSAwLTM4TDQ5NCAyOTUuOWMxMC41LTEwLjUgMjcuNS0xMC41IDM4IDBsMTM0LjUgMTM0LjVjMTAuNSAxMC40IDEwLjUgMjcuNSAwIDM4eiIgZmlsbD0iIzE1NzJlZiIgcC1pZD0iMTIxOSI+PC9wYXRoPjwvc3ZnPg==\');z-index:999;opacity:0.9;"></a>'; $("body").append(ahtml); $("#toTop").scrollToTop(300); });

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.