PageSourceSearch

https://daohang-c5k.pages.dev/soso/js/set.js

js daohang-c5k.pages.dev collected 2026-10-03 06:39:52 UTC 45,107 bytes, 1,403 lines download raw bytes

1/*
2作者:D.Young
3主页:https://yyv.me/
4github:https://github.com/5iux/sou
5日期:2019-07-26
6版权所有,请勿删除
7========================================
8由 yeetime 修改
9github:https://github.com/yeetime/sou2
10日期:2019-12-13
11========================================
12由 imsyy 二次修改
13github:https://github.com/imsyy/sou2
14日期:2022-03-10
15*/
16
17// 默认搜索引擎列表
18var se_list_preinstall = {
19    '1': {
20        id: 1,
21        title: "百度",
22        url: "https://www.baidu.com/s",
23        name: "wd",
24        icon: "iconfont icon-baidu",
25    },
26    '2': {
27        id: 2,
28        title: "必应",
29        url: "https://cn.bing.com/search",
30        name: "q",
31        icon: "iconfont icon-bing",
32    },
33    '3': {
34        id: 3,
35        title: "谷歌",
36        url: "https://www.google.com/search",
37        name: "q",
38        icon: "iconfont icon-google",
39    },
40    '4': {
41        id: 4,
42        title: "搜狗",
43        url: "https://www.sogou.com/web",
44        name: "query",
45        icon: "iconfont icon-sougousousuo",
46    },
47    '5': {
48        id: 5,
49        title: "360",
50        url: "https://www.so.com/s",
51        name: "q",
52        icon: "iconfont icon-360sousuo",
53    },
54    '6': {
55        id: 6,
56        title: "微博",
57        url: "https://s.weibo.com/weibo",
58        name: "q",
59        icon: "iconfont icon-xinlangweibo",
60    },
61    '7': {
62        id: 7,
63        title: "知乎",
64        url: "https://www.zhihu.com/search",
65        name: "q",
66        icon: "iconfont icon-zhihu",
67    },
68    '8': {
69        id: 8,
70        title: "Github",
71        url: "https://github.com/search",
72        name: "q",
73        icon: "iconfont icon-github",
74    },
75    '9': {
76        id: 9,
77        title: "BiliBili",
78        url: "https://search.bilibili.com/all",
79        name: "keyword",
80        icon: "iconfont icon-bilibilidonghua",
81    },
82    '10': {
83        id: 10,
84        title: "淘宝",
85        url: "https://s.taobao.com/search",
86        name: "q",
87        icon: "iconfont icon-taobao",
88    },
89    '11': {
90        id: 11,
91        title: "京东",
92        url: "https://search.jd.com/Search",
93        name: "keyword",
94        icon: "iconfont icon-jingdong",
95    }
96};
97
98// 默认快捷方式
99var quick_list_preinstall = {
100    '1': {
101        title: "Vercel",
102        url: "https://vercel.com/",
103    },
104    '2': {
105        title: "GitHub",
106        url: "https://github.com/",
107    },
108    '3': {
109        title: "Cloudflare",
110        url: "https://dash.cloudflare.com/",
111    },
112    '4': {
113        title: "W3school",
114        url: "https://www.w3school.com.cn/",
115    },
116    '5': {
117        title: "腾讯云",
118        url: "https://console.cloud.tencent.com/",
119    },
120    '6': {
121        title: "阿里云",
122        url: "https://console.aliyun.com/",
123    },
124    '7': {
125        title: "百度网盘",
126        url: "https://pan.baidu.com/",
127    },
128    '8': {
129        title: "阿里云盘",
130        url: "https://www.aliyundrive.com/drive/",
131    },
132    '9': {
133        title: "Office",
134        url: "https://www.office.com/",
135    },
136    '10': {
137        title: "又拍云",
138        url: "https://console.upyun.com/",
139    },
140    '11': {
141        title: "CSDN",
142        url: "https://www.csdn.net/",
143    },
144    '12': {
145        title: "哔哩哔哩",
146        url: "https://www.bilibili.com/",
147    }
148};
149
150// 项目设置
151var project_settings_preinstall = {
152    show_weather: "1",
153    show_welcome: "1",
154    auto_focus: "0",
155    show_aplayer: "1",
156    music_playlist_id: "2141128031",
157};
158
159function canUseLocalStorage() {
160    try {
161        var testKey = "__soso_test__";
162        localStorage.setItem(testKey, "1");
163        localStorage.removeItem(testKey);
164        return true;
165    } catch (error) {
166        return false;
167    }
168}
169
170function readStore(key) {
171    if (canUseLocalStorage()) {
172        var localValue = localStorage.getItem(key);
173        if (localValue !== null && localValue !== undefined) {
174            return localValue;
175        }
176    }
177    return Cookies.get(key);
178}
179
180function writeStore(key, value) {
181    var raw = typeof value === "string" ? value : JSON.stringify(value);
182    if (canUseLocalStorage()) {
183        localStorage.setItem(key, raw);
184    }
185    Cookies.set(key, raw, {
186        expires: 36500,
187        sameSite: "Lax"
188    });
189}
190
191function getStoreObject(key, fallback) {
192    var localValue = readStore(key);
193    if (!localValue || localValue === "{}") {
194        writeStore(key, fallback);
195        return JSON.parse(JSON.stringify(fallback));
196    }
197    try {
198        return JSON.parse(localValue);
199    } catch (error) {
200        writeStore(key, fallback);
201        return JSON.parse(JSON.stringify(fallback));
202    }
203}
204
205function getStoreValue(key, fallback) {
206    var localValue = readStore(key);
207    if (localValue === undefined || localValue === null || localValue === "") {
208        writeStore(key, String(fallback));
209        return String(fallback);
210    }
211    return String(localValue);
212}
213
214// 获取搜索引擎列表
215function getSeList() {
216    return getStoreObject('se_list', se_list_preinstall);
217}
218
219// 设置搜索引擎列表
220function setSeList(se_list) {
221    if (se_list) {
222        writeStore('se_list', se_list);
223        return true;
224    }
225    return false;
226}
227
228// 获得默认搜索引擎
229function getSeDefault() {
230    return getStoreValue('se_default', "1");
231}
232
233//背景图片
234var bg_img_preinstall = {
235    "type": "1", // 1:使用主题默认的背景图片 2:必应每日 3:随机风景 4:随机二次元 5:自定义图片
236    "path": "", //自定义图片
237};
238
239// 获取背景图片
240function getBgImg() {
241    return getStoreObject('bg_img', bg_img_preinstall);
242}
243
244// 设置背景图片
245function setBgImg(bg_img) {
246    if (bg_img) {
247        writeStore('bg_img', bg_img);
248        return true;
249    }
250    return false;
251}
252
253function getProjectSettings() {
254    var settings = getStoreObject('project_settings', project_settings_preinstall);
255    if (!settings || typeof settings !== "object" || Array.isArray(settings)) {
256        settings = JSON.parse(JSON.stringify(project_settings_preinstall));
257        setProjectSettings(settings);
258        return settings;
259    }
260    // 确保所有预设键都存在,如果不存在则使用默认值
261    var changed = false;
262    for (var key in project_settings_preinstall) {
263        if (settings[key] === undefined || settings[key] === null) {
264            settings[key] = project_settings_preinstall[key];
265            changed = true;
266        }
267    }
268    var boolKeys = ["show_weather", "show_welcome", "auto_focus", "show_aplayer"];
269    for (var i = 0; i < boolKeys.length; i++) {
270        var boolKey = boolKeys[i];
271        var boolValue = String(settings[boolKey]);
272        if (boolValue !== "0" && boolValue !== "1") {
273            settings[boolKey] = project_settings_preinstall[boolKey];
274            changed = true;
275        }
276    }
277    var playlistId = String(settings.music_playlist_id || "").trim();
278    if (!/^\d+$/.test(playlistId)) {
279        settings.music_playlist_id = project_settings_preinstall.music_playlist_id;
280        changed = true;
281    }
282    if (changed) {
283        setProjectSettings(settings);
284    }
285    return settings;
286}
287
288function setProjectSettings(projectSettings) {
289    if (projectSettings) {
290        writeStore('project_settings', projectSettings);
291        return true;
292    }
293    return false;
294}
295
296function isSettingEnabled(value) {
297    return value === "1" || value === 1 || value === true || value === "true";
298}
299
300function applyProjectSettings() {
301    var projectSettings = getProjectSettings();
302    var hideWeather = !isSettingEnabled(projectSettings.show_weather);
303    $(".weather").toggle(!hideWeather);
304    if (isSettingEnabled(projectSettings.auto_focus) && window.innerWidth > 768) {
305        setTimeout(function () {
306            $(".wd").focus();
307            focusWd();
308        }, 200);
309    }
310    var $aplayer = $("#aplayer-wrap");
311    if ($aplayer.length) {
312        var shouldShowAplayer = isSettingEnabled(projectSettings.show_aplayer);
313        $aplayer.toggle(shouldShowAplayer);
314        if (shouldShowAplayer) {
315            var playlistId = String(projectSettings.music_playlist_id || "").trim();
316            if (!/^\d+$/.test(playlistId)) {
317                playlistId = "2141128031";
318                projectSettings.music_playlist_id = playlistId;
319                setProjectSettings(projectSettings);
320                $(".set-project-option[data-setting='music_playlist_id']").val(playlistId);
321            }
322            var $meting = $aplayer.find("meting-js");
323            var currentId = String($meting.attr("id") || $aplayer.attr("data-playlist-id") || "").trim();
324            
325            if (currentId !== playlistId) {
326                // ID 发生了变化,需要重新加载播放器
327                if (typeof window.loadAPlayerAssets === "function") {
328                    window.loadAPlayerAssets(true);
329                }
330            } else if (typeof window.loadAPlayerAssets === "function") {
331                window.loadAPlayerAssets();
332            }
333        }
334    }
335    return projectSettings;
336}
337
338function setProjectSettingsInit() {
339    var projectSettings = getProjectSettings();
340    $(".set-project-option").each(function () {
341        var settingKey = $(this).attr("data-setting");
342        if (settingKey && projectSettings[settingKey] !== undefined) {
343            if ($(this).is(":checkbox")) {
344                $(this).prop("checked", isSettingEnabled(projectSettings[settingKey]));
345            } else {
346                $(this).val(projectSettings[settingKey]);
347            }
348        }
349    });
350}
351
352// 设置-壁纸
353//$('#bg').attr('src','https://api.dujin.org/bing/1920.php')
354function setBgImgInit() {
355    var bg_img = getBgImg();
356    $("input[name='wallpaper-type'][value=" + bg_img["type"] + "]").click();
357    if (bg_img["type"] === "5") {
358        $("#wallpaper-url").val(bg_img["path"]);
359        $("#wallpaper-button").fadeIn(100);
360        $("#wallpaper_url").fadeIn(100);
361    } else {
362        $("#wallpaper_url").fadeOut(300);
363        $("#wallpaper-button").fadeOut(300);
364    }
365
366    switch (bg_img["type"]) {
367        case "1":
368            var pictures = new Array();
369            pictures[0] = './img/background1.webp';
370            pictures[1] = './img/background2.webp';
371            pictures[2] = './img/background3.webp';
372            pictures[3] = './img/background4.webp';
373            pictures[4] = './img/background5.webp';
374            pictures[5] = './img/background6.webp';
375            pictures[6] = './img/background7.webp';
376            pictures[7] = './img/background8.webp';
377            pictures[8] = './img/background9.webp';
378            pictures[9] = './img/background10.webp';
379            var rd = Math.floor(Math.random() * 10);
380            $('#bg').attr('src', pictures[rd]) //随机默认壁纸
381            break;
382        case "2":
383            $('#bg').attr('src', 'https://api.dujin.org/bing/1920.php') //必应每日
384            break;
385        case "3":
386            $('#bg').attr('src', 'https://api.ixiaowai.cn/gqapi/gqapi.php') //随机风景
387            break;
388        case "4":
389            $('#bg').attr('src', 'https://api.ixiaowai.cn/api/api.php') //随机二次元
390            break;
391        case "5":
392            $('#bg').attr('src', bg_img["path"]) //自定义
393            break;
394    }
395}
396
397// 搜索框高亮
398function focusWd() {
399    $("body").addClass("onsearch");
400}
401
402// 搜索框取消高亮
403function blurWd() {
404    $("body").removeClass("onsearch");
405    //隐藏输入
406    $(".wd").val("");
407    //隐藏搜索建议
408    $("#keywords").hide();
409}
410
411// 搜索建议提示
412function keywordReminder() {
413    var keyword = $(".wd").val();
414    if (keyword != "") {
415        $.ajax({
416            url: 'https://suggestion.baidu.com/su?wd=' + keyword,
417            dataType: 'jsonp',
418            jsonp: 'cb', //回调函数的参数名(键值)key
419            success: function (data) {
420                //获取宽度
421                $("#keywords").css("width", $('.sou').width());
422                $("#keywords").empty().show();
423                $.each(data.s, function (i, val) {
424                    $('#keywords').append(`<div class="keyword" data-id="${i + 1}"><i class='iconfont icon-sousuo'></i>${val}</div>`);
425                });
426                $("#keywords").attr("data-length", data.s["length"]);
427                $(".keyword").click(function () {
428                    $(".wd").val($(this).text());
429                    $("#search-submit").click();
430                });
431            },
432            error: function () {
433                $("#keywords").empty().show();
434                $("#keywords").hide();
435            }
436        })
437    } else {
438        $("#keywords").empty().show();
439        $("#keywords").hide();
440    }
441}
442
443// 搜索框数据加载
444function searchData() {
445    var se_default = getSeDefault();
446    var se_list = getSeList();
447    var defaultSe = se_list[se_default];
448    if (defaultSe) {
449        $(".search").attr("action", defaultSe["url"]);
450        $("#icon-se").attr("class", defaultSe["icon"]);
451        $(".wd").attr("name", defaultSe["name"]);
452    }
453
454    // 判断窗口大小,添加输入框自动完成
455    // var wid = $("body").width();
456    // if (wid < 640) {
457    //     $(".wd").attr('autocomplete', 'off');
458    // } else {
459    //     $(".wd").focus();
460    //     focusWd();
461    // }
462}
463
464// 搜索引擎列表加载
465function seList() {
466    var html = "";
467    var se_list = getSeList();
468    for (var i in se_list) {
469        html += `<div class='se-li' data-url='${se_list[i]["url"]}' data-name='${se_list[i]["name"]}' data-icon='${se_list[i]["icon"]}'>
470        <a class='se-li-text'><i id='icon-sou-list' class='${se_list[i]["icon"]}'></i><span>${se_list[i]["title"]}</span></a></div>`;
471    }
472    $(".search-engine-list").html(html);
473}
474
475// 设置-搜索引擎列表加载
476function setSeInit() {
477    var se_default = getSeDefault();
478    var se_list = getSeList();
479    var html = "";
480    for (var i in se_list) {
481        var tr = `<div class='se_list_div'><div class='se_list_num'>${i}</div>`;
482        if (i === se_default) {
483            tr = `<div class='se_list_div'><div class='se_list_num'>
484            <i class='iconfont icon-home'></i></div>`;
485        }
486        tr += `<div class='se_list_name'>${se_list[i]["title"]}</div>
487        <div class='se_list_button'>
488        <button class='set_se_default' value='${i}' style='border-radius: 8px 0px 0px 8px;'>
489        <i class='iconfont icon-home'></i></button>
490        <button class='edit_se' value='${i}'>
491        <i class='iconfont icon-xiugai'></i></button>
492        <button class='delete_se' value='${i}' style='border-radius: 0px 8px 8px 0px;'>
493        <i class='iconfont icon-delete'></i></button></div>
494        </div>`;
495        html += tr;
496    }
497    $(".se_list_table").html(html);
498}
499
500// 获取快捷方式列表
501function getQuickList() {
502    return getStoreObject('quick_list', quick_list_preinstall);
503}
504
505// 设置快捷方式列表
506function setQuickList(quick_list) {
507    if (quick_list) {
508        writeStore('quick_list', quick_list);
509        return true;
510    }
511    return false;
512}
513
514// 快捷方式数据加载
515function quickData() {
516    var html = "";
517    var quick_list = getQuickList();
518    for (var i in quick_list) {
519        html += `<div class="quick">
520                    <a href="${quick_list[i]['url']}" target="_blank">${quick_list[i]['title']}</a>
521                </div>`;
522    }
523    $(".quick-all").html(html + `<div class="quick"><a id="set-quick"><i class="iconfont icon-tianjia-"></i></a></div>`);
524}
525
526// 设置-快捷方式加载
527function setQuickInit() {
528    var quick_list = getQuickList();
529    var html = "";
530    for (var i in quick_list) {
531        tr = `
532        <div class='quick_list_div'>
533            <div class='quick_list_div_num'>${i}</div>
534            <div class='quick_list_div_name'>${quick_list[i]['title']}</div>
535            <div class='quick_list_div_button'>
536                <button class='edit_quick' value='${i}' style='border-radius: 8px 0px 0px 8px;'>
537                <i class='iconfont icon-xiugai'></i></button>
538                <button class='delete_quick' value='${i}' style='border-radius: 0px 8px 8px 0px;'>
539                <i class='iconfont icon-delete'></i></button>
540            </div>
541        </div>`;
542        html += tr;
543    }
544    $(".quick_list_table").html(html);
545}
546
547/**
548 * 下载文本为文件
549 * @param filename 文件名
550 * @param text     内容
551 */
552function download(filename, text) {
553    var element = document.createElement('a');
554    element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
555    element.setAttribute('download', filename);
556
557    element.style.display = 'none';
558    document.body.appendChild(element);
559
560    element.click();
561
562    document.body.removeChild(element);
563}
564
565// 打开设置
566function openSet() {
567    $("#menu").addClass('on');
568
569    openBox();
570
571    //更改设置图标
572    $("#icon-menu").attr("class", "iconfont icon-home");
573
574    //隐藏书签打开设置
575    $(".mark").css({
576        "display": "none",
577    });
578    $(".set").css({
579        "display": "flex",
580    });
581}
582
583// 关闭设置
584function closeSet() {
585    $("#menu").removeClass('on');
586
587    closeBox();
588
589    //更改设置图标
590    $("#icon-menu").attr("class", "iconfont icon-shezhi");
591
592    //隐藏设置
593    $(".set").css({
594        "display": "none",
595    });
596
597    // 刷新主页数据
598    seList();
599    quickData();
600}
601
602// 书签显示
603function openBox() {
604    $("#content").addClass('box');
605    $(".mark").css({
606        "display": "flex",
607    });
608    //时间上移
609    $(".tool-all").css({
610        "transform": 'translateY(-160%)'
611    });
612    //背景模糊
613    $('#bg').css({
614        "transform": 'scale(1.08)',
615        "filter": "blur(4px)",
616        "transition": "ease 0.3s",
617    });
618}
619
620// 书签关闭
621function closeBox() {
622    $("#content").removeClass('box');
623    $(".mark").css({
624        "display": "none",
625    });
626    //时间下移
627    $(".tool-all").css({
628        "transform": 'translateY(-110%)'
629    });
630    //背景模糊
631    $('#bg').css({
632        "transform": 'scale(1)',
633        "filter": "blur(0px)",
634        "transition": "ease 0.3s",
635    });
636}
637
638//显示设置搜索引擎列表
639function showSe() {
640    $(".se_list").show();
641    $(".se_add_preinstall").show();
642}
643
644//隐藏设置搜索引擎列表
645function hideSe() {
646    $(".se_list").hide();
647    $(".se_add_preinstall").hide();
648}
649
650//显示设置快捷方式列表
651function showQuick() {
652    $(".quick_list").show();
653    $(".se_add_preinstalls").show();
654}
655
656//隐藏设置快捷方式列表
657function hideQuick() {
658    $(".quick_list").hide();
659    $(".se_add_preinstalls").hide();
660}
661
662
663$(document).ready(function () {
664
665    // 项目设置初始化
666    applyProjectSettings();
667    setProjectSettingsInit();
668
669    // 搜索框数据加载
670    searchData();
671
672    // 搜索引擎列表加载
673    seList();
674
675    // 快捷方式数据加载
676    quickData();
677
678    // 壁纸数据加载
679    setBgImgInit();
680
681    // 点击事件
682    $(document).on('click', function (e) {
683        // 选择搜索引擎点击
684        if ($(".search-engine").is(":hidden") && $(".se").is(e.target) || $(".search-engine").is(":hidden") && $("#icon-se").is(e.target)) {
685            if ($(".se").is(e.target) || $("#icon-se").is(e.target)) {
686                //获取宽度
687                $(".search-engine").css("width", $('.sou').width() - 30);
688                //出现动画
689                $(".search-engine").slideDown(160);
690            }
691        } else {
692            if (!$(".search-engine").is(e.target) && $(".search-engine").has(e.target).length === 0) {
693                $(".search-engine").slideUp(160);
694            }
695        }
696
697        // 自动提示隐藏
698        if (!$(".sou").is(e.target) && $(".sou").has(e.target).length === 0) {
699            $("#keywords").hide();
700        }
701    });
702
703    // 时间点击
704    $("#time_text").click(function () {
705        if ($("#content").attr("class") === "box") {
706            closeBox();
707            closeSet();
708            blurWd();
709        } else {
710            openBox();
711        }
712    });
713
714    // 搜索引擎列表点击
715    $(".search-engine-list").on("click", ".se-li", function () {
716        var url = $(this).attr('data-url');
717        var name = $(this).attr('data-name');
718        var icon = $(this).attr('data-icon');
719        $(".search").attr("action", url);
720        $(".wd").attr("name", name);
721        $("#icon-se").attr("class", icon);
722        $(".search-engine").slideUp(160);
723    });
724
725    // 搜索引擎列表点击
726    $(".search-engine-list").on("click", ".se-li", function () {
727        var url = $(this).attr('data-url');
728        var name = $(this).attr('data-name');
729        var icon = $(this).attr('data-icon');
730        $(".search").attr("action", url);
731        $(".wd").attr("name", name);
732        $("#icon-se").attr("class", icon);
733        $(".search-engine").slideUp(160);
734    });
735
736    // 搜索框点击事件
737    $(document).on('click', '.sou', function () {
738        focusWd();
739        $(".search-engine").slideUp(160);
740    });
741
742    $(document).on('click', '.wd', function () {
743        focusWd();
744        keywordReminder();
745        $(".search-engine").slideUp(160);
746    });
747
748    // 点击其他区域关闭事件
749    $(document).on('click', '.close_sou', function () {
750        blurWd();
751        closeSet();
752    });
753
754    // 点击搜索引擎时隐藏自动提示
755    $(document).on('click', '.se', function () {
756        $('#keywords').toggle();
757    });
758
759    // 恢复自动提示
760    $(document).on('click', '.se-li', function () {
761        $('#keywords').show();
762    });
763
764    // 自动提示 (调用百度 api)
765    $('.wd').keyup(function (event) {
766        var key = event.keyCode;
767        // 屏蔽上下键
768        var shieldKey = [38, 40];
769        if (shieldKey.includes(key)) return;
770        keywordReminder();
771    });
772
773    // 点击自动提示的搜索建议
774    $("#keywords").on("click", ".wd", function () {
775        var wd = $(this).text();
776        $(".wd").val(wd);
777        $(".search").submit();
778        //隐藏输入
779        $(".wd").val("");
780        $("#keywords").hide();
781    });
782
783    // 自动提示键盘方向键选择操作
784    $(".wd").keydown(function (event) { //上下键获取焦点
785        var key = event.keyCode;
786        if ($.trim($(this).val()).length === 0) return;
787
788        var id = $(".choose").attr("data-id");
789        if (id === undefined) id = 0;
790
791        if (key === 38) {
792            /*向上按钮*/
793            id--;
794        } else if (key === 40) {
795            /*向下按钮*/
796            id++;
797        } else {
798            return;
799        }
800        var length = $("#keywords").attr("data-length");
801        if (id > length) id = 1;
802        if (id < 1) id = length;
803
804        $(".keyword[data-id=" + id + "]").addClass("choose").siblings().removeClass("choose");
805        $(".wd").val($(".keyword[data-id=" + id + "]").text());
806    });
807
808    // 菜单点击
809    $("#menu").click(function () {
810        if ($(this).attr("class") === "on") {
811            closeSet();
812        } else {
813            openSet();
814
815            // 设置内容加载
816            setSeInit(); //搜索引擎设置
817            setQuickInit(); //快捷方式设置
818        }
819    });
820
821    // 快捷方式添加按钮点击(动态元素,使用事件委托)
822    $(document).on("click", "#set-quick", function (event) {
823        event.preventDefault();
824        openSet();
825
826        // 设置内容加载
827        setSeInit(); //搜索引擎设置
828        setQuickInit(); //快捷方式设置
829
830        //添加快捷方式
831        $("#set-quick-menu").trigger('click');
832        $(".set_quick_list_add").trigger('click');
833    });
834
835    // NOISE导航主页按钮:回到主页状态
836    $(document).on("click", "#brand-home, #set-home-link", function (event) {
837        event.preventDefault();
838        closeSet();
839        closeBox();
840        blurWd();
841        window.location.href = "../index.html";
842    });
843
844    // 修改默认搜索引擎
845    $(".se_list_table").on("click", ".set_se_default", function () {
846        var name = $(this).val();
847        iziToast.show({
848            timeout: 8000,
849            message: '是否设置为默认搜索引擎?',
850            buttons: [
851                ['<button>确认</button>', function (instance, toast) {
852                    writeStore('se_default', name);
853                    setSeInit();
854                    instance.hide({
855                        transitionOut: 'flipOutX',
856                    }, toast, 'buttonName');
857                    iziToast.show({
858                        message: '设置成功'
859                    });
860                    setTimeout(function () {
861                        window.location.reload()
862                    }, 1000);
863                }, true],
864                ['<button>取消</button>', function (instance, toast) {
865                    instance.hide({
866                        transitionOut: 'flipOutX',
867                    }, toast, 'buttonName');
868                }]
869            ]
870        });
871    });
872
873    // 搜索引擎添加
874    $(".set_se_list_add").click(function () {
875        $(".se_add_content input").val("");
876
877        hideSe();
878        $(".se_add_content").show();
879    });
880
881    // 搜索引擎保存
882    $(".se_add_save").click(function () {
883        var key_inhere = $(".se_add_content input[name='key_inhere']").val();
884        var key = $(".se_add_content input[name='key']").val();
885        var title = $(".se_add_content input[name='title']").val();
886        var url = $(".se_add_content input[name='url']").val();
887        var name = $(".se_add_content input[name='name']").val();
888        //var icon = $(".se_add_content input[name='icon']").val();
889        var icon = "iconfont icon-wangluo";
890
891        var num = /^\+?[1-9][0-9]*$/;
892        if (!num.test(key)) {
893            iziToast.show({
894                timeout: 2000,
895                message: '序号 ' + key + ' 不是正整数'
896            });
897            return;
898        }
899
900        var se_list = getSeList();
901
902        if (se_list[key]) {
903            iziToast.show({
904                timeout: 8000,
905                message: '搜索引擎 ' + key + ' 已有数据,是否覆盖?',
906                buttons: [
907                    ['<button>确认</button>', function (instance, toast) {
908                        se_list[key] = {
909                            title: title,
910                            url: url,
911                            name: name,
912                            icon: icon,
913                        };
914                        setSeList(se_list);
915                        setSeInit();
916                        $(".se_add_content").hide();
917                        //显示列表
918                        showSe();
919
920                        instance.hide({
921                            transitionOut: 'flipOutX',
922                        }, toast, 'buttonName');
923                        iziToast.show({
924                            message: '覆盖成功'
925                        });
926                    }, true],
927                    ['<button>取消</button>', function (instance, toast) {
928                        instance.hide({
929                            transitionOut: 'flipOutX',
930                        }, toast, 'buttonName');
931                    }]
932                ]
933            });
934            return;
935        }
936
937        if (key_inhere && key !== key_inhere) {
938            delete se_list[key_inhere];
939        }
940
941        se_list[key] = {
942            title: title,
943            url: url,
944            name: name,
945            icon: icon,
946        };
947        setSeList(se_list);
948        setSeInit();
949        iziToast.show({
950            timeout: 2000,
951            message: '添加成功'
952        });
953        $(".se_add_content").hide();
954        showSe();
955    });
956
957    // 关闭表单
958    $(".se_add_cancel").click(function () {
959        $(".se_add_content").hide();
960
961        //显示列表
962        showSe();
963    });
964
965    // 搜索引擎修改
966    $(".se_list").on("click", ".edit_se", function () {
967
968        var se_list = getSeList();
969        var key = $(this).val();
970        $(".se_add_content input[name='key_inhere']").val(key);
971        $(".se_add_content input[name='key']").val(key);
972        $(".se_add_content input[name='title']").val(se_list[key]["title"]);
973        $(".se_add_content input[name='url']").val(se_list[key]["url"]);
974        $(".se_add_content input[name='name']").val(se_list[key]["name"]);
975        // $(".se_add_content input[name='icon']").val("iconfont icon-Earth");
976
977        //隐藏列表
978        hideSe();
979
980        $(".se_add_content").show();
981    });
982
983    // 搜索引擎删除
984    $(".se_list").on("click", ".delete_se", function () {
985        var se_default = getSeDefault();
986        var key = $(this).val();
987        if (key == se_default) {
988            iziToast.show({
989                message: '默认搜索引擎不可删除'
990            });
991        } else {
992            iziToast.show({
993                timeout: 8000,
994                message: '搜索引擎 ' + key + ' 是否删除?',
995                buttons: [
996                    ['<button>确认</button>', function (instance, toast) {
997                        var se_list = getSeList();
998                        delete se_list[key];
999                        setSeList(se_list);
1000                        setSeInit();
1001                        instance.hide({
1002                            transitionOut: 'flipOutX',
1003                        }, toast, 'buttonName');
1004                        iziToast.show({
1005                            message: '删除成功'
1006                        });
1007                    }, true],
1008                    ['<button>取消</button>', function (instance, toast) {
1009                        instance.hide({
1010                            transitionOut: 'flipOutX',
1011                        }, toast, 'buttonName');
1012                    }]
1013                ]
1014            });
1015        }
1016    });
1017
1018    // 恢复预设搜索引擎
1019    $(".set_se_list_preinstall").click(function () {
1020        iziToast.show({
1021            timeout: 8000,
1022            message: '现有搜索引擎数据将被清空',
1023            buttons: [
1024                ['<button>确认</button>', function (instance, toast) {
1025                    setSeList(se_list_preinstall);
1026                    writeStore('se_default', "1");
1027                    setSeInit();
1028                    instance.hide({
1029                        transitionOut: 'flipOutX',
1030                    }, toast, 'buttonName');
1031                    iziToast.show({
1032                        message: '重置成功'
1033                    });
1034                    setTimeout(function () {
1035                        window.location.reload()
1036                    }, 1000);
1037                }, true],
1038                ['<button>取消</button>', function (instance, toast) {
1039                    instance.hide({
1040                        transitionOut: 'flipOutX',
1041                    }, toast, 'buttonName');
1042                }]
1043            ]
1044        });
1045    });
1046
1047    // 设置-快捷方式添加
1048    $(".set_quick_list_add").click(function () {
1049        $(".quick_add_content input").val("");
1050        $(".quick_add_content").show();
1051
1052        //隐藏列表
1053        hideQuick();
1054    });
1055
1056    // 设置-快捷方式保存
1057    $(".quick_add_save").click(function () {
1058        var key_inhere = $(".quick_add_content input[name='key_inhere']").val();
1059        var key = $(".quick_add_content input[name='key']").val();
1060        var title = $(".quick_add_content input[name='title']").val();
1061        var url = $(".quick_add_content input[name='url']").val();
1062        var img = $(".quick_add_content input[name='img']").val();
1063
1064        var num = /^\+?[1-9][0-9]*$/;
1065        if (!num.test(key)) {
1066            iziToast.show({
1067                timeout: 2000,
1068                message: '快捷方式 ' + key + ' 不是正整数'
1069            });
1070            return;
1071        }
1072
1073        var quick_list = getQuickList();
1074
1075        if (quick_list[key]) {
1076            iziToast.show({
1077                timeout: 8000,
1078                message: '快捷方式 ' + key + ' 已有数据,是否覆盖?',
1079                buttons: [
1080                    ['<button>确认</button>', function (instance, toast) {
1081                        quick_list[key] = {
1082                            title: title,
1083                            url: url,
1084                            img: img,
1085                        };
1086                        setQuickList(quick_list);
1087                        setQuickInit();
1088                        $(".quick_add_content").hide();
1089                        //显示列表
1090                        showQuick();
1091
1092                        instance.hide({
1093                            transitionOut: 'flipOutX',
1094                        }, toast, 'buttonName');
1095                        iziToast.show({
1096                            message: '覆盖成功'
1097                        });
1098                    }, true],
1099                    ['<button>取消</button>', function (instance, toast) {
1100                        instance.hide({
1101                            transitionOut: 'flipOutX',
1102                        }, toast, 'buttonName');
1103                    }]
1104                ]
1105            });
1106            return;
1107        }
1108
1109        if (key_inhere && key != key_inhere) {
1110            delete quick_list[key_inhere];
1111        }
1112
1113        quick_list[key] = {
1114            title: title,
1115            url: url,
1116            img: img,
1117        };
1118        setQuickList(quick_list);
1119        setQuickInit();
1120        $(".quick_add_content").hide();
1121        iziToast.show({
1122            timeout: 2000,
1123            message: '添加成功'
1124        });
1125
1126        //显示列表
1127        showQuick();
1128    });
1129
1130    // 设置-快捷方式关闭添加表单
1131    $(".quick_add_cancel").click(function () {
1132        $(".quick_add_content").hide();
1133
1134        //显示列表
1135        showQuick();
1136    });
1137
1138    //恢复预设快捷方式
1139    $(".set_quick_list_preinstall").click(function () {
1140        iziToast.show({
1141            timeout: 8000,
1142            message: '快捷方式数据将被清空',
1143            buttons: [
1144                ['<button>确认</button>', function (instance, toast) {
1145                    setQuickList(quick_list_preinstall);
1146                    setQuickInit();
1147                    instance.hide({
1148                        transitionOut: 'flipOutX',
1149                    }, toast, 'buttonName');
1150                    iziToast.show({
1151                        timeout: 2000,
1152                        message: '重置成功'
1153                    });
1154                    // setTimeout(function () {
1155                    //     window.location.reload()
1156                    // }, 1000);
1157                }, true],
1158                ['<button>取消</button>', function (instance, toast) {
1159                    instance.hide({
1160                        transitionOut: 'flipOutX',
1161                    }, toast, 'buttonName');
1162                }]
1163            ]
1164        });
1165    });
1166
1167    // 快捷方式修改
1168    $(".quick_list").on("click", ".edit_quick", function () {
1169
1170        var quick_list = getQuickList();
1171        var key = $(this).val();
1172        $(".quick_add_content input[name='key_inhere']").val(key);
1173        $(".quick_add_content input[name='key']").val(key);
1174        $(".quick_add_content input[name='title']").val(quick_list[key]["title"]);
1175        $(".quick_add_content input[name='url']").val(quick_list[key]["url"]);
1176        $(".quick_add_content input[name='img']").val(quick_list[key]["img"]);
1177
1178        //隐藏列表
1179        hideQuick();
1180
1181        $(".quick_add_content").show();
1182    });
1183
1184    // 快捷方式删除
1185    $(".quick_list").on("click", ".delete_quick", function () {
1186
1187        var key = $(this).val();
1188
1189        iziToast.show({
1190            timeout: 8000,
1191            message: '快捷方式 ' + key + ' 是否删除?',
1192            buttons: [
1193                ['<button>确认</button>', function (instance, toast) {
1194                    var quick_list = getQuickList();
1195                    delete quick_list[key];
1196                    setQuickList(quick_list);
1197                    setQuickInit();
1198                    instance.hide({
1199                        transitionOut: 'flipOutX',
1200                    }, toast, 'buttonName');
1201                    iziToast.show({
1202                        timeout: 2000,
1203                        message: '删除成功'
1204                    });
1205                }, true],
1206                ['<button>取消</button>', function (instance, toast) {
1207                    instance.hide({
1208                        transitionOut: 'flipOutX',
1209                    }, toast, 'buttonName');
1210                }]
1211            ]
1212        });
1213    });
1214
1215    // 壁纸设置
1216    $("#wallpaper").on("click", ".set-wallpaper", function () {
1217        var type = $(this).val();
1218        var bg_img = getBgImg();
1219        bg_img["type"] = type;
1220
1221        if (type === "1") {
1222            $('#wallpaper_text').html("显示默认壁纸,刷新页面以生效");
1223            setBgImg(bg_img);
1224            iziToast.show({
1225                message: '壁纸设置成功,刷新生效',
1226            });
1227        }
1228
1229        if (type === "2") {
1230            $('#wallpaper_text').html("显示必应每日一图,每天更新,刷新页面以生效 | API @ 缙哥哥");
1231            setBgImg(bg_img);
1232            iziToast.show({
1233                message: '壁纸设置成功,刷新生效',
1234            });
1235        }
1236
1237        if (type === "3") {
1238            $('#wallpaper_text').html("显示随机风景图,每次刷新后更换,刷新页面以生效 | API @ 小歪");
1239            setBgImg(bg_img);
1240            iziToast.show({
1241                message: '壁纸设置成功,刷新生效',
1242            });
1243        }
1244
1245        if (type === "4") {
1246            $('#wallpaper_text').html("显示随机二次元图,每次刷新后更换,刷新页面以生效 | API @ 小歪");
1247            setBgImg(bg_img);
1248            iziToast.show({
1249                message: '壁纸设置成功,刷新生效',
1250            });
1251        }
1252
1253        if (type === "5") {
1254            $('#wallpaper_text').html("自定义壁纸地址,请输入正确地址,点击保存且刷新页面以生效");
1255            $("#wallpaper_url").fadeIn(100);
1256            $("#wallpaper-button").fadeIn(100);
1257            $("#wallpaper-url").val(bg_img["path"]);
1258        } else {
1259            $("#wallpaper_url").fadeOut(300);
1260            $("#wallpaper-button").fadeOut(300);
1261        }
1262    });
1263
1264    // 自定义壁纸设置保存
1265    $(".wallpaper_save").click(function () {
1266        var url = $("#wallpaper-url").val();
1267        var reg = /^http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- ./?%&=]*)?$/;
1268        if (!reg.test(url)) {
1269            iziToast.show({
1270                message: '请输入正确的链接',
1271            });
1272        } else {
1273            var bg_img = getBgImg();
1274            bg_img["type"] = "5";
1275            bg_img["path"] = url;
1276            setBgImg(bg_img);
1277            iziToast.show({
1278                message: '自定义壁纸设置成功,刷新生效',
1279            });
1280        }
1281    });
1282
1283    // 项目设置保存
1284    $("#project_settings_save").click(function () {
1285        var currentSettings = getProjectSettings();
1286        $(".set-project-option").each(function () {
1287            var settingKey = $(this).attr("data-setting");
1288            if (settingKey) {
1289                if ($(this).is(":checkbox")) {
1290                    currentSettings[settingKey] = $(this).is(":checked") ? "1" : "0";
1291                } else {
1292                    var settingValue = String($(this).val() || "").trim();
1293                    if (settingKey === "music_playlist_id" && !/^\d+$/.test(settingValue)) {
1294                        settingValue = "2141128031";
1295                        $(this).val(settingValue);
1296                    }
1297                    currentSettings[settingKey] = settingValue;
1298                }
1299            }
1300        });
1301        setProjectSettings(currentSettings);
1302        applyProjectSettings();
1303        iziToast.show({
1304            timeout: 2000,
1305            message: '项目设置已保存'
1306        });
1307    });
1308
1309    // 我的数据导出
1310    $("#my_data_out").click(function () {
1311        var backupData = {
1312            cookies: Cookies.get(),
1313            localStorage: {}
1314        };
1315        if (canUseLocalStorage()) {
1316            for (var i = 0; i < localStorage.length; i++) {
1317                var storageKey = localStorage.key(i);
1318                backupData.localStorage[storageKey] = localStorage.getItem(storageKey);
1319            }
1320        }
1321        var json = JSON.stringify(backupData);
1322        download("Noisedh-back-up-" + $.now() + ".json", json);
1323        iziToast.show({
1324            timeout: 2000,
1325            message: '已导出备份文件至下载目录'
1326        });
1327    });
1328
1329    // 我的数据导入 点击触发文件选择
1330    $("#my_data_in").click(function () {
1331        $("#my_data_file").click();
1332    });
1333
1334    // 选择文件后读取文件内容
1335    $("#my_data_file").change(function () {
1336        var selectedFile = document.getElementById('my_data_file').files[0];
1337        //var name = selectedFile.name;//读取选中文件的文件名
1338        //var size = selectedFile.size;//读取选中文件的大小
1339        //console.log("文件名:"+name+" 大小:"+size);
1340
1341        var reader = new FileReader(); //这是核心,读取操作就是由它完成.
1342        reader.readAsText(selectedFile); //读取文件的内容,也可以读取文件的URL
1343        reader.onload = function () {
1344            //当读取完成后回调这个函数,然后此时文件的内容存储到了result中,直接操作即可
1345            //console.log(this.result);
1346
1347            // json 格式校验
1348            var mydata;
1349            try {
1350                mydata = JSON.parse(this.result);
1351            } catch (e) {
1352                iziToast.show({
1353                    timeout: 2000,
1354                    message: '数据解析异常'
1355                });
1356                return;
1357            }
1358            if (typeof mydata != 'object') {
1359                iziToast.show({
1360                    timeout: 2000,
1361                    message: '数据格式错误'
1362                });
1363                return;
1364            }
1365
1366            iziToast.show({
1367                timeout: 8000,
1368                message: '当前数据将会被覆盖!是否继续导入?',
1369                buttons: [
1370                    ['<button>确认</button>', function (instance, toast) {
1371                        var cookieData = mydata.cookies ? mydata.cookies : mydata;
1372                        for (var key in cookieData) {
1373                            writeStore(key, cookieData[key]);
1374                        }
1375                        if (mydata.localStorage && canUseLocalStorage()) {
1376                            for (var localKey in mydata.localStorage) {
1377                                localStorage.setItem(localKey, mydata.localStorage[localKey]);
1378                            }
1379                        }
1380                        instance.hide({
1381                            transitionOut: 'flipOutX',
1382                        }, toast, 'buttonName');
1383                        iziToast.show({
1384                            timeout: 2000,
1385                            message: '导入成功'
1386                        });
1387                        setTimeout(function () {
1388                            window.location.reload()
1389                        }, 1000);
1390                    }, true],
1391                    ['<button>取消</button>', function (instance, toast) {
1392                        instance.hide({
1393                            transitionOut: 'flipOutX',
1394                        }, toast, 'buttonName');
1395                        setTimeout(function () {
1396                            window.location.reload()
1397                        }, 1000);
1398                    }]
1399                ]
1400            });
1401        }
1402    });
1403});

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.