两个小时写了一个无广告版:百度搜索

效果见图:

不为别的,怕家人搜索到不该搜索的东西、致命的毒药,医院....

代码逻辑目前比较简单,只实现了接口调用,还没有进行过多逻辑判断,这里跟大家分享的目的也是希望人人都能使用安全卫生的搜索环境:

完整代码:(需要油猴浏览器插件)
背景图是采集的bing.com的,会动态跟随变化。

// ==UserScript==
// @name         jsoncode的安全模式
// @namespace    test
// @version      0.1
// @description  提供一个安全环境访问互联网
// @author       jsoncode
// @match        http://**/*
// @match        https://**/*
// @require      https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js
// @grant        GM_xmlhttpRequest
// @grant        GM.getResourceUrl
// @grant        unsafeWindow
// @run-at       document-start ==/ document-end context-menu==
// ==/UserScript==

var q = jQuery.noConflict();
(function() {
    if (location.host == 'www.baidu.com') {
        baidu_setTitle();
        baidu_clearBody();
        addStyle();
        addHtml();
        // 搜索框
        var input = q('#search-input');
        // 关键词列表
        var inputList = q('#search-input-list');
        // 搜索按钮
        var searchBtn = q('#searchBtn');
        // 搜索结果
        var content = q('#content—result');
        // 搜索分页
        var pagination = q('#pagination');

        input.focus();
        input.on('keydown', function(e) {
            if (e.keyCode === 38 || e.keyCode === 40) {
                baidu_upAndDown(e);
                inputList.show();
            } else if (e.keyCode === 13) {
                baidu_search(input.val())
                inputList.hide();
            } else {
                var searchKeyword = q(this).val();
                baidu_getKeyWord(searchKeyword);
                inputList.show();
            }
        });

        searchBtn.click(function() {
            baidu_search(input.val());
        });

        q(document).click(function(e) {
            baidu_toggleList(e);
        });
        setTimeout(function() {
            console.clear();
            q('[href*="bdstatic"],[src*="bdstatic"]').remove();
        }, 1000);
    }


    function addStyle() {
        q('head').append('');
        var style = `
            
            `;
        q('head').append(style);
    }

    function addHtml() {
        q('body').css({
            overflow: 'hidden'
        }).append(`
            
    `); } function baidu_setTitle(title) { document.title = title || '安全搜索-广告已过滤' } function baidu_clearBody() { document.head.innerHTML = ''; document.body.innerHTML = ''; getBg(function(img) { q('body').css({ backgroundImage:`url(${img})` }) }); } function baidu_getKeyWord(keyword, back) { var callback = back || function() {}; var t1 = new Date().getTime(); var t2 = t1 + 210; inputList.show(); GM_xmlhttpRequest({ method: 'GET', url: `https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd=${keyword}&json=1&p=3&sid=26524_1464_21098_26350_22160&req=2&bs=&csor=3&pwd=cs&cb=jQuery110208264721847970322_${t1}&_=${t2}`, onload: function(response) { var objStr = response.responseText.match(/(?<=[\w+])\(([\s\S]+)(?=\))/)[1].replace(/\\'/g, "'"); var list = JSON.parse(objStr).s; list = list.concat(['视频', '图片', 'api'].map(function(item) { return keyword + ' ' + item; })); var html = ''; list.forEach(function(item, i) { html += '
  • ' + item + '
  • '; }); inputList.html(html); callback() }, onerror: function(reponse) { alert('error'); } }); } function baidu_search(value) { if (value === null || value === '') { return; } GM_xmlhttpRequest({ method: 'GET', url: `https://www.baidu.com/s?ie=utf-8&mod=11&isbd=1&isid=10FCC76279E92878&ie=utf-8&f=8&rsv_bp=0&rsv_idx=1&tn=baidu&wd=${encodeURIComponent(value)}&rsv_pq=ab4cc49200041a6f&rsv_t=8dfcL6IoYXAYa2vQiTntndpQUwLw3pJRQXVhnn9xy30VSdRSNNnie3QwINA&rqlang=cn&rsv_enter=1&rsv_sug3=6&rsv_sug1=6&rsv_sug7=101&rsv_sid=26524_1464_21098_26350_22160&_ss=1&clist=&hsug=%E5%89%8D%E7%AB%AF%E5%B7%A5%E7%A8%8B%E5%B8%88&csor=2&pstg=5&_cr1=28874`, onload: function(response) { var str = response.responseText.replace(/(data-click|style|tpl)="[^"]+"|