Greasy Fork is available in English.

百度搜索去广告+百度页面美化【代码最精简高效】

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

Versão de: 03/07/2020. Veja: a última versão.

// ==UserScript==
// @name         百度搜索去广告+百度页面美化【代码最精简高效】
// @description  代码精简,无垃圾推广!快速去除百度结果页的顽固广告和右边栏,适当放大了界面,采用居中布局,美化了字体等样式,页面显示更加美观;为了精简代码以及提高性能,没有加任何定时器脚本,没有任何购物推荐啥的,最大程度减少系统资源消耗。
// @icon         http://baidu.com/favicon.ico
// @namespace    https://greasyfork.org/zh-CN/users/393603-tsing
// @version      2.0
// @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        none
// ==/UserScript==

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

    var style_tag = document.createElement('style');
    style_tag.innerHTML = 'body{zoom:1.15} #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{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;} .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;}';
    document.head.appendChild(style_tag);

    document.addEventListener ("DOMContentLoaded", kill_baidu_ad);
    function kill_baidu_ad () {
        $(document).ajaxSuccess(function(e, xhr, opt) { // 点击百度一下按钮,采用的是ajax更新网页内容和url
            document.head.appendChild(style_tag); console.log("ajax");
            $('#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);
        });

        $(".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(" ");
    }

})();