shumin-baidu

自用,卡片样式抄改自https://gf.qytechs.cn/zh-CN/scripts/406336

当前为 2023-03-07 提交的版本,查看 最新版本

// ==UserScript==
// @name         shumin-baidu
// @description  自用,卡片样式抄改自https://gf.qytechs.cn/zh-CN/scripts/406336
// @icon         http://baidu.com/favicon.ico
// @namespace    https://gf.qytechs.cn/zh-CN/
// @version      5.0.0
// @author       qianjunlang
// @license      MIT
// @run-at       document-start
// @match        *://*.baidu.com/s?*
// @match        *://*.baidu.com/baidu?*
// @require      https://cdn.bootcdn.net/ajax/libs/jquery/3.6.3/jquery.js
// @grant        GM_xmlhttpRequest
// @connect      baidu.com
// @compatible   edge
// @compatible   chrome
// @compatible   safari

// ==/UserScript==

function check_emp(x) {
  return x.length > 0;
}
function get_s_wd(){
    var wd = "NONE"
    var qry = window.location.search.substring(1);
    var vals = qry.split('&');
    for(var i in vals){
        var pair = vals[i].split('=');
        if(pair[0] == "wd") wd = pair[1];
    }

    wd = wd.replace(/%20/g,'+');
    wd = wd.split('+').filter(check_emp).join('+');

    if(vals.length > 2) window.history.replaceState(null,null, 'https://'+ window.location.hostname +'/s?wd=' + wd);

    return wd;
}
function change_style(){
    var css = `
        #s_main, .s-top-nav, .s-hotsearch-wrapper, #content_right {
            display: none;
        }
        #container #content_left {
            width: 1000px !important;
        }
        @media screen and (min-width: 1921px) {
            #container.sam_newgrid {
                padding-left: 0 !important;
                width: 1000px !important;
            }
            .wrapper_new #s_tab.s_tab .s_tab_inner {
                padding-left: 0 !important;
                margin-left: -36px;
            }
            .wrapper_new #head .s_form:not(div#s_fm.s_form), .s-isindex-wrap {
                margin-left: -60px !important;
            }
            .wrapper_new #s_tab, #page > div, #ent_sug {
                width: 1000px !important;
            }
            .foot-container_2X1Nt div {
                width: 1000px !important;
            }
        }
        .new-pmd.c-container, #container #content_left .result-op, #container #content_left .result {
            width: 980px !important;
        }
        .new-pmd .c-span12 {
            width: 970px !important;
        }
        .new-pmd .c-span9 {
            width: 820px !important;
        }
        #container .c-container h3.t > a:first-child, #container .c-container h3.t > a:first-child em, #container .c-container .c-title > a:first-child, #container .c-container .c-title > a:first-child em {
            text-decoration: none !important;
            line-height: 1.3 !important
        }
        .nums, .new_search_tool_conter {
            width: 1000px !important;
        }
        #container.sam_newgrid {
            margin-left: unset !important;
            margin: 0 auto !important;
        }
        #container #content_left .result-op, #container #content_left .result {
            border-radius: 10px !important;
            box-shadow: 0 0 6px #eeeeff;
            border-left: 1px solid #eeeeee;
            padding: 10px 10px 15px 20px !important;
            transition: margin-bottom 0.6s, padding-bottom 0.6s, box-shadow 0.2s;
        }
        #container #content_left .result-op:hover, #container #content_left .result:hover {
            box-shadow: 1px 1px 10px #cccccc;
            border-radius: 0;
        }
        .new-pmd .c-border {
            box-shadow: unset !important
        }
        .wrapper_new #s_tab, #page > div, #ent_sug {
            padding-left: 0 !important;
            width: 1080px;
            margin: 0 auto !important;
        }
        #ent_sug {
            margin-top: 140px !important;
        }
        #help {
            display: block;
            width: 1080px;
            margin: 0 auto;
            float: unset !important;
            padding-left: unset !important;
        }
        #head .head_wrapper {
            width: 1080px;
            margin: 0 auto !important;
        }
        .wrapper_new #head .s_form:not(div#s_fm.s_form), .s-isindex-wrap {
            margin-left: 0;
        }
        .wrapper_new #head .s_form {
            padding-left: 0 !important;
        }
        .slowmsg1 {
            left: 400px !important;
            top: 120px !important;
            box-shadow: none !important;
            border: none !important;
            background: none !important;
        }
        div[class^="re-box_"] {
            box-shadow: none !important;
        }
    `;

    if (typeof GM_addStyle != "undefined") GM_addStyle(css);
    else if (typeof PRO_addStyle != "undefined") PRO_addStyle(css);
    else if (typeof addStyle != "undefined") addStyle(css);
    else{
        var node = document.createElement("style");
        node.type = "text/css";
        node.appendChild(document.createTextNode(css));
        var heads = document.getElementsByTagName("head");
        if (heads.length > 0) {
            heads[0].appendChild(node);

            var style_tag = document.createElement('style');
            style_tag.innerHTML = css;
            document.head.appendChild(style_tag);

        } else {
            document.documentElement.appendChild(node);// no head yet, stick it whereever
        }
    }
}
function fresh_page(){

    change_style();

    $("#u a.toindex").text("=> Google");
    $("#u a.toindex").attr('href','https://www.google.com/search?q='+ get_s_wd());

    //$("#content_right").remove();

    `for(let it of $('h3 > a'))
        try{
            GM_xmlhttpRequest({
                extData: 'https://www.baidu.com/',
                url: it.href+'&wd=&eqid=',
                headers: {"Accept": "*/*", "Referer": 'https://www.baidu.com/'},
                method: "GET",
                timeout: 100,
                onreadystatechange: (response)=>{
                    if(response.responseText) {
                        it.href = (/URL='([^']+)'/ig).exec(response.responseText)[1];
                        return
                    }
                }
            });
        }catch(error){}`

}
function kill_baidu () {
    fresh_page();
    unsafeWindow.$(document).ajaxSuccess(function(e, xhr, opt) { // Microsoft Edge 和 Safari 不支持 $(document).ajaxSuccess()
        fresh_page();
        $('#content_left>div').has('span:contains("广告")').remove();
        setTimeout(function () { $('.c-container').has('.f13>span:contains("广告")').remove(); }, 2100); // 去除顽固性的延迟加载广告,一般延迟2秒左右。例如搜索“淘宝”,当页面加载完毕之后在搜索结果最前或最后会再插入一个广告。
    });
}

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*main*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
(function() {
    /* global $ */
    'use strict';
    
//一次性操作合集

    //change_style();
    fresh_page();

    document.getElementById("head").style.height="50px";
    document.getElementById("form").style.marginTop="5px";
    document.getElementById("u").style.marginTop="-5px";
    document.getElementById("result_logo").style.marginTop="5px";

    //window.onload = kill_baidu();
    //$(document).ready()

//一旦页面发生改变,立刻补救
    document.addEventListener ("DOMContentLoaded", kill_baidu());
    window.addEventListener('popstate', kill_baidu());
    window.onhashchange = kill_baidu();

    //$("#kw").keydown(function (e){ if (e.keyCode == 13){ kill_baidu(); //e.preventDefault();// 取消之前的keydown事件}})

})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址