Greasy Fork is available in English.

百度搜索去广告+百度页面美化+支持百度黑色主题【代码精简高效】

代码精简,无垃圾推广!快速去除百度结果页的顽固广告和右边栏,适当放大了界面,采用居中布局,美化了字体等样式,页面显示更加美观,支持随时开启/关闭黑色主题;为了精简代码以及提高性能,没有加任何定时器脚本,没有任何购物推荐啥的,最大程度减少系统资源消耗。

Fra og med 08.07.2020. Se Den nyeste version.

// ==UserScript==
// @name         百度搜索去广告+百度页面美化+支持百度黑色主题【代码精简高效】
// @description  代码精简,无垃圾推广!快速去除百度结果页的顽固广告和右边栏,适当放大了界面,采用居中布局,美化了字体等样式,页面显示更加美观,支持随时开启/关闭黑色主题;为了精简代码以及提高性能,没有加任何定时器脚本,没有任何购物推荐啥的,最大程度减少系统资源消耗。
// @icon         http://baidu.com/favicon.ico
// @namespace    https://greasyfork.org/zh-CN/users/393603-tsing
// @version      2.7
// @author       Tsing
// @run-at       document-start
// @include      *://ipv6.baidu.com/s?*
// @include      *://www.baidu.com/s?*
// @include      *://www.baidu.com/
// @require      https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_registerMenuCommand
// @copyright    该脚本完全由 Tsing@greasyfork 原创,谢绝抄袭部分或全部代码!如有借鉴代码,请声明并标注脚本链接。如发现有人抄袭,欢迎举报,谢谢。
// ==/UserScript==

(function() {
    /* global $ */
    'use strict';

    var style_tag = document.createElement('style');
    var white_style = 'body{zoom:1.15} #s_main, .s-top-nav, .s-hotsearch-wrapper, #content_right{display:none;} #content_left{padding-left:0 !important; width:1000px !important; margin:0 auto; float:none;} #rs{padding:0 !important; margin:0 auto !important; width:900px !important;} #rs table{width:640px !important;} #page .page-inner{padding-left:0 !important; display:block; width:900px !important; margin:0 auto !important;} #page a{margin-right:20px !important;} #foot #help{display:block; width:900px; margin:0 auto !important; float:none !important; padding-left:0 !important;} #content_left a, #rs a{color: #3C50B4; text-decoration: none !important; } .se_st_footer a{color:#008000;} .m{color:#666666 !important;} em{color: #FA3232; text-decoration: none !important;} .t a{font-size: 1.1em;} a.c-text{color:#ffffff !important; font-size:0.8em !important;} #kw{font-size: 1.5em !important;} .search_tool_conter, .nums{width: 900px !important; margin:0 auto !important;} .c-container{width:900px !important; margin:0 auto; padding:10px 15px 15px 15px; border-radius: 10px; box-shadow:1px 1px 6px #eeeeff; transition:padding 0.5s ease, box-shadow 0.5s ease, border-radius 0.5s ease-out;} .c-container:hover{box-shadow:1px 1px 10px #cccccc; border-radius:0;} .c-span-last p a{font-size: 1.1em;} #rs_top_new, .hit_top_new{width:900px !important; margin:0 auto !important;} .c-result-content article{width: 100% !important; padding: 0 !important; box-shadow: none;} .c-result-content article:hover{box-shadow:none;} .c-border{box-shadow:none !important; width:880px;} .op-img-portrait-menu .op-img-portrait-text-public{color:#ffffff !important;} .head_wrapper{width: 1196px; margin: 0 auto; position: relative;} #container{box-sizing: border-box; width: 1000px; margin: 0 auto;} .c-border.ec-pl-container {width: 900px; margin: 0 auto; margin-bottom: 15px; padding: 15px; border-radius: 15px; box-shadow: 0 0 4px #eeeeff !important; border: none; display:none;} .op-img-address-link-type{margin-right:10px;} .c-span18{width:760px !important;} .c-span24{width:890px !important;} #s_tab{padding-left:0 !important;} #s_tab.s_tab .s_tab_inner{ display: block; box-sizing: border-box; padding: 0; width: 900px; margin: 0 auto;} .op-img-address-link-type a{margin-right:10px !important;} .op-img-portrait-item-con{padding:5px;} .c-border .c-span6{margin-bottom:10px; border:1px solid #dddddd;} .op-img-portrait-pic-more{text-align:left !important;} .op_exactqa_tag_item{color:#3C50B4 !important;} span.op_exactqa_tag_item.op_exactqa_tag_selected.OP_LOG_BTN{color:#ffffff !important;} .wenda-abstract-wrap{margin-bottom:0 !important; border:none !important;} .hint_common_restop{width:900px !important; margin:0 auto !important;} .wenda-abstract-img-wrap{display:none;} #content_left .c-group{width:900px !important; margin-bottom: 15px !important; padding: 10px 15px 15px 15px !important; border: none !important;} .op-short-video-pc-img-group{max-height:none !important;} .result { width: 900px; word-break: break-all; word-wrap: break-word; box-shadow: 0 0 6px #eeeeff; padding: 10px 15px 15px 15px; margin:0 auto; border-radius: 10px; transition: all 0.5s;} .result:hover{box-shadow:1px 1px 10px #cccccc; border-radius:0;} #header_top_bar, .tab-wrapper, #gotoPage, p#page{width:900px; margin:0 auto;} #header_top_bar{padding:15px;} #gotoPage{margin-bottom:20px;} p#page{padding:0;} form.fm{font-size:11px;} .op-gk-topic-header-imgc, .op-gk-topic-banners{display:none !important;} div[class$="op_rs"]{width:900px !important; margin:0 auto; margin-bottom:15px;} div[class$="op_rs_left"]{width:auto;}';
    var dark_style = 'body{zoom:1.15; color:#eeeeee; background-color:#1a1a1a !important;} #rs{background-color:#1a1a1a !important;} .wrapper_new #head, .foot-inner, .wrapper_new .container_new~#page{background-color:#222222;} #s_main, .s-top-nav, .s-hotsearch-wrapper, #content_right{display:none;} #content_left{padding-left:0 !important; width:1000px !important; margin:0 auto; float:none;} #rs{padding:0 !important; margin:0 auto !important; width:900px !important;} #rs table{width:640px !important;} #page .page-inner{padding-left:0 !important; display:block; width:900px !important; margin:0 auto !important;} #page a{margin-right:20px !important;} .wrapper_new #foot #help, #foot #help{display:block; width:900px; margin:0 auto !important; float:none !important; padding-left:0 !important;} #content_left h3 a, .subLink_answer a, #rs a{color: #eeeeee; text-decoration: none !important; } .se_st_footer a{color:#008000;} .m{color:#aaaaaa !important;} .c-container em, .result em{color: #eeeeee !important; text-decoration: none !important;} .t a{font-size: 1.1em;} .c-border.ec-pl-container {width: 900px; margin: 0 auto; margin-bottom: 15px; padding: 15px; border-radius: 15px; border: 1px solid #222222 !important; display:none;} a.c-text{color:#ffffff !important; font-size:0.8em !important;} #kw{font-size: 1.5em !important; color:#ffffff;} .bdsug.bdsug-new, .bdsug.bdsug-new.bdsugbg{background-color:#222222 !important;} .wrapper_new #form .bdsug-new ul li{color:#8888ff;} .wrapper_new #form .bdsug-new ul li b{color:#cccccc;} .wrapper_new #form .bdsug-new ul{border-top:2px solid #333333;} .soutu-env-result #form .s_ipt_wr{border-color:#444444;} .wrapper_new .s_ipt_wr{overflow:hidden !important; border-color:#444444;} .wrapper_new #u>a{color:#eeeeee;} .c-table td{border-bottom:1px solid #444444;} .c-table th{border-color:#444444; background:none;} .search_tool_conter, .nums{width: 900px !important; margin:0 auto !important;} .wrapper_new #s_tab a{color:#cccccc;} .wrapper_new #s_tab .s-tab-item:hover, .wrapper_new #s_tab .s-tab-item:hover:before{color:#ffffff;} .wrapper_new #s_tab .cur-tab, .wrapper_new #s_tab .cur-tab:before{color:#ffffff;} .c-container{width:900px !important; margin:0 auto; padding:10px 15px 15px 15px; border-radius: 10px; border:1px solid #222222; transition:padding 0.5s ease, border 0.5s ease, border-radius 0.5s ease-out;} .c-container:hover{border:1px solid #444444; border-radius:0;} .c-container a{color:#cccccc; text-decoration:none;} .c-span-last p a{font-size: 1.1em;} #rs_top_new, .hit_top_new{width:900px !important; margin:0 auto !important;} .c-result-content article{width: 100% !important; padding: 0 !important; box-shadow: none;} .c-result-content article:hover{box-shadow:none;} .c-border{box-shadow:none !important; border:none; width:880px;} .wrapper_new .container_new~#page a{color:#5599ff; background-color:#282828;} #foot, #foot #help{background-color:#222222 !important; border-top:none;} .wa-zp-exact-new-current{background-color:#444444 !important;} .wa-zp-exact-new-border{border:1px solid #444444 !important;} .wa-zp-exact-new-topline{border-top:1px solid #444444 !important;} .wa-zp-exact-new-table{background:none !important;} .wa-zp-exact-new-bline{border:none !important;} .wa-zp-exact-new-gray-a, .wa-zp-exact-new-color{color:#eeeeee !important;} .wa-zp-exact-new-aurl{color:#8888ff !important;} .search_tool:hover, .search_tool_conter span:hover{color:#cccccc !important;} .op_dict3_highlight{color:#ff8888 !important;} .op_dict3_inlineblock{color:#cccccc !important;} .op-img-portrait-menu .op-img-portrait-text-public{color:#ffffff !important;} .head_wrapper{width: 1196px; margin: 0 auto; position: relative;} #container{box-sizing: border-box; width: 1000px; margin: 0 auto;} .op-img-address-link-type{margin-right:10px;} .c-span18{width:760px !important;} .c-span24{width:890px !important;} #s_tab{padding-left:0 !important; background-color:#222222;} #s_tab.s_tab .s_tab_inner{ display: block; box-sizing: border-box; padding: 0; width: 900px; margin: 0 auto;} .c-showurl{color:#88ff88;} .nvl-bookstore-wrap .chapter-list{border-top:solid 1px #444444 !important;} .nvl-bookstore-wrap .chapter-item{border-bottom:solid 1px #444444 !important;} .nvl-bookstore-wrap .chapter-title, .nvl-bookstore-wrap .bookinfo-text{color:#cccccc !important; text-decoration:none !important;} .op-img-address-link-type a{margin-right:10px !important;} .op-img-portrait-item-con{padding:5px;} .c-border .c-span6{margin-bottom:10px; border:1px solid #444444;} .OP_LOG_BTN{background-color:#1a1a1a !important; color:#cccccc !important;} .op-stockdynamic-moretab-map-tip, .op-stockdynamic-moretab-map, .op-stockdynamic-moretab-map-tag{background-color:#222222 !important;} .op-stockdynamic-moretab-map-tip{border:none !important;} .op-stockdynamic-moretab-tabs-nav .op-stockdynamic-moretab-tabs-nav-selected{border:1px solid #444444 !important;} .op-stockdynamic-moretab-tabs-nav li{border-left:1px solid #444444 !important;} .c-tabs-nav .c-tabs-nav-selected{border-color:#444444 !important;} .c-tabs-nav{background-color:#1a1a1a !important; border:none !important;} .c-tabs-nav li{border-width:2px !important;} .c-tabs-nav .c-tabs-nav-sep{border:none !important;} .op-video-vast-ul li.op-video-vast-smallicon-li{border-bottom:1px solid #444444 !important;} .op-video-vast-border{border:none !important;} .op-video-vast-ul li.op-video-vast-smallicon-li a span i{color:#eeeeee !important;} .op-img-portrait-pic-more{text-align:left !important;} .wenda-abstract-wrap{margin-bottom:0 !important; border:none !important;} #bottom_layer, .s-top-wrap{background:none !important;} .c-color-gray2, .c-color-t{color:#cccccc !important;} #head_wrapper #kw{background-color:#222222 !important; border-color:#444444; color:#eeeeee;} #head_wrapper #form .bdsug-new ul li, #head_wrapper #form .bdsug-new ul li b{color:#cccccc !important;} #head_wrapper #form .bdsug-new ul{border-top:2px solid #444444;} #head_wrapper .soutu-btn{background-color:#222222;} .op_dict3_extra{border-top:1px solid #444444 !important;} .op-mapcity-gray{background-color:#222222; color:#cccccc !important; border-color:#444444;} .c-input:hover{box-shadow:none;} .f13 a, .c, .c-row span{color:#888888 !important;} .op_exactqa_title{color:#cccccc !important;} .opui-page-more, .opui-page-number-now{color:#cccccc;} #_mask{opacity:0 !important;} .wenda-abstract-img-wrap{display:none;} .wenda-abstract-short-answer h3{color:#cccccc !important;} #head_wrapper .under-tips .links-link{color:#cccccc;} .op-timeliness-abs, .op_sp_realtime_subabs{color:#cccccc !important;} .c-divider .thin{background-color:#444444 !important;} .op-documents-tr-first{border-color:#444444 !important;} #content_left .c-group{width:900px !important; margin-bottom: 15px !important; padding: 10px 15px 15px 15px !important; border: 1px solid #222222 !important;} .op_sp_realtime_subabs em{color:#cccccc !important;} .op-short-video-pc-img-group{max-height:none !important;} .result { width: 900px; word-break: break-all; word-wrap: break-word; border:1px solid #222222; padding: 10px 15px 15px 15px; margin:0 auto; border-radius: 10px; transition: all 0.5s;} .result:hover{border:1px solid #444444; border-radius:0;} #header_top_bar, .tab-wrapper, #gotoPage, p#page{width:900px; margin:0 auto;} #header_top_bar{padding:15px;} #gotoPage{margin-bottom:20px;} p#page{padding:0;} form.fm{font-size:11px;} .s_ipt_wr{background-color:#222222;} .soutu-env-index span.bg.s_ipt_wr.quickdelete-wrap{border:none !important;} .c-summary.c-row{color:#eeeeee;} #head{background-color:#222222; border-bottom:none;} .bdsug{width:539px; background-color:#222222; border:1px solid #444444; box-shadow:none; background-image:none !important;} .bdsug li{color:#cccccc;} .bdsug li.bdsug-s{background-color:#333333; width:518px;} .s_btn:hover, .s_btn.btnhover{box-shadow:none;} #u a{color:#cccccc;} #s_tab a{color:#888888;} #s_tab a:hover, #s_tab b{color:#eeeeee;} #gotoPS{color:#cccccc;} .PS-word{color:#ff8888;} #page a, #page strong{background:none;} #page .pc{background-color:#333333; border:1px solid #444444; color:#cccccc;} #head.s_down{box-shadow: 0 0 5px #1a1a1a;} #page strong .pc, #page .n:hover, #page a:hover .pc{background:none;} #page .n{border:none; color:#cccccc;} .nors .tip_head, .nors li, .content_none .nors p{color:#cccccc;} .nors p em{color:#ff5555;} .nors li a{color:#5555ff;} .op-gk-topic-body-border{background:none !important; border:none !important;} .op-gk-topic-title{color:#eeeeee !important;} .op-gk-topic-bigdata-item .title, .op-gk-topic-news-item .content{color:#cccccc !important;} .op-gk-topic-header-imgc, .op-gk-topic-banners{display:none !important;} .tab-nav-name{background:none !important;} div[class$="op_rs"]{width:900px !important; margin:0 auto; margin-bottom:15px;} div[class$="op_rs_left"]{width:auto;} div[class$="op_rs"] a{color:#cccccc;}';
    style_tag.innerHTML = white_style;
    document.head.appendChild(style_tag);

    document.addEventListener ("DOMContentLoaded", kill_baidu_ad);
    function kill_baidu_ad () {
        unsafeWindow.$(document).ajaxSuccess(function(e, xhr, opt) { // Microsoft Edge 和 Safari 不支持 $(document).ajaxSuccess()
            document.head.appendChild(style_tag);
            $('#content_left>div').has('span:contains("广告")').remove();
            setTimeout(function () { $('.c-container').has('.f13>span:contains("广告")').remove(); }, 2100); // 去除顽固性的延迟加载广告,一般延迟2秒左右。例如搜索“淘宝”,当页面加载完毕之后在搜索结果最前或最后会再插入一个广告。
        });
        $("#s-usersetting-top").mouseover(function(){ // 由于body放大,导致首页上的设置弹出框位置错乱,百度的UI设计能不能走点心。。。
            var offset_right = $(document).width()/1.15 - $("#s-usersetting-top").offset().left - $("#s-usersetting-top").width()/2 - $("#s-user-setting-menu").width()/2; // 计算公式参考百度官方代码:https://ss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K/r/www/cache/static/protocol/https/home/js/nu_instant_search_7422ef2.js
            setTimeout(function () { $("#s-user-setting-menu").css("right", offset_right); }, 0);
        });
        $("#head_wrapper").addClass("s-ps-islite"); // 登录了账号之后首页有可能出现资讯信息流,以下强制关闭。
        if(document.getElementsByClassName("hide-feed").length){ // 不允许开启资讯信息流
            $("#s-user-setting-menu .show-feed:first").css("display", "none"); setTimeout(function () { document.getElementsByClassName("hide-feed")[0].click(); }, 1000); // 原生click()才可以
        }
        if(document.getElementsByClassName("set-hide").length){ // 热榜关闭
            setTimeout(function () { document.getElementsByClassName("set-hide")[0].click(); $("#s-user-setting-menu .set-show:first").css("display", "none");}, 1000);
        }
        try{
            $(".op_exactqa_item.c-gap-bottom.c-span6.c-span-last").removeClass("c-span-last"); // 电影简介图布局错误,例如搜索:电影
            $(".c-span6.c-span-last.op-img-portrait-item-con").removeClass("c-span-last"); // 百度图片的重新排列,例如搜索:头像
            var arr = $(".op-img-portrait-con .c-row.c-gap-top"); var html = [];
            for(var i=0;i<arr.length;i++){
                html[i] = arr[i].innerHTML; if(i > 0){ arr[i].remove(); }
            }
            arr[0].innerHTML = html.join(" ");
        }catch(e){}
    }

    var dark_mode = GM_getValue("dark_mode_on");
    if(dark_mode){ style_tag.innerHTML = dark_style; }else{ style_tag.innerHTML = white_style; }

    GM_registerMenuCommand ("切换明亮模式/黑色模式", dark_func, "");
    function dark_func () {
        if(dark_mode){ GM_setValue("dark_mode_on", false); location.reload(); }else{ GM_setValue("dark_mode_on", true); location.reload(); }
    }

    GM_registerMenuCommand ("打赏支持脚本开发者", menu_func, "");
    function menu_func () {
        window.open("https://greasyfork.org/zh-CN/users/393603-tsing");
    }

})();