Greasy Fork is available in English.

百度知道美化

展开所有回答并居中显示

Version au 26/07/2020. Voir la dernière version.

// ==UserScript==
// @name         百度知道美化
// @namespace    http://tampermonkey.net/
// @version      0.5
// @description  展开所有回答并居中显示
// @author       AN drew
// @match        https://zhidao.baidu.com/*
// @require      https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js
// @grant        none
// ==/UserScript==

function execCoy(text) {
    const input = document.createElement('textarea');
    input.style.opacity  = 0;
    input.style.position = 'absolute';
    input.style.left = '-100000px';
    document.body.appendChild(input);

    input.value = text;
    input.select();
    input.setSelectionRange(0, text.length);
    document.execCommand('copy');
    document.body.removeChild(input);
    return true;
}


(function() {

    var $copy_button = $('<div class="copy-button">复制</div>');
    $copy_button.attr("style","display: none;"+
                      "right: 4px !important;"+
                      "top: 4px !important;"+
                      "width: 25px !important;"+
                      "height: 14px !important;"+
                      "font-size: 12px !important;"+
                      "vertical-align: center !important;"+
                      "color: #4d4d4d !important;"+
                      "background-color: white !important;"+
                      "padding: 2px 8px !important;"+
                      "margin: 8px !important;"+
                      "border-radius: 4px !important;"+
                      "cursor: pointer !important;"+
                      "user-select: none;"+
                      "box-shadow: 0 2px 4px rgba(0,0,0,0.1), 0 2px 4px rgba(0,0,0,0.1) !important;");

    setTimeout(function(){
        $(".syntaxhighlighter .code").after($copy_button);
        $(".syntaxhighlighter").hover(function(){
            var code="";
            var code_children = $(this).find(".container").children();

            for(let i=0; i<code_children.length; i++)
            {
                code+=code_children.eq(i).text()+"\n";
            }

            //&nbsp;转正常空格
            code = encodeURI(code)
            code = code.replace(/%C2%A0/g,'%20');
            code = decodeURI(code);

            $(this).find(".copy-button").css("display","block");
            $(this).find(".copy-button").click(function(){
                 for(let k=0 ; k<code.length; k++)
                     console.log(code[k]+" "+code[k].charCodeAt(0).toString(16))
                execCoy(code);
                $(this).text("复制成功");
                $(this).attr("style","display: block;"+
                      "right: 4px !important;"+
                      "top: 4px !important;"+
                      "width: 48px !important;"+
                      "height: 14px !important;"+
                      "font-size: 12px !important;"+
                      "vertical-align: center !important;"+
                      "color: #4d4d4d !important;"+
                      "background-color: white !important;"+
                      "padding: 2px 8px !important;"+
                      "margin: 8px !important;"+
                      "border-radius: 4px !important;"+
                      "cursor: pointer !important;"+
                      "user-select: none;"+
                      "box-shadow: 0 2px 4px rgba(0,0,0,0.1), 0 2px 4px rgba(0,0,0,0.1) !important;");
            })
        },function(){
                $(this).find(".copy-button").text("复制");
                $(this).find(".copy-button").attr("style","display: none;"+
                                                  "right: 4px !important;"+
                                                  "top: 4px !important;"+
                                                  "width: 25px !important;"+
                                                  "height: 14px !important;"+
                                                  "font-size: 12px !important;"+
                                                  "vertical-align: center !important;"+
                                                  "color: #4d4d4d !important;"+
                                                  "background-color: white !important;"+
                                                  "padding: 2px 8px !important;"+
                                                  "margin: 8px !important;"+
                                                  "border-radius: 4px !important;"+
                                                  "cursor: pointer !important;"+
                                                  "user-select: none;"+
                                                  "box-shadow: 0 2px 4px rgba(0,0,0,0.1), 0 2px 4px rgba(0,0,0,0.1) !important;");
        })
    },1500);

    setInterval(function(){
        if($(".wgt-best-mask").css("display")=="block")
            $(".wgt-best-showbtn").click()

        $(".wgt-answers-mask").each(function(){
            if($(this).css("display")=="block")
                $(this).find(".wgt-answers-showbtn").click()
        })

        $(".jump-goto-star").attr("style","display:none; visibility:hidden; position:absolute; top:-1000px;");
    },1000)


    setTimeout(function(){
        $(".show-hide-dispute").click()
        $(".replyask-extandup-btn").click()
        $("a.f-green").parent().parent().parent().removeAttr("style")
        if($(".expend").get(0)!=null && $(".expend").hasClass("expend_hide")==false)
            $(".expend").get(0).click()
        var $wenku = $("a.f-green").parent().parent()
        var $wenkuclone = $wenku.clone(true)
        $wenku.remove()
        $wenkuclone.find(".wgt-best-open-wenku").css({"text-align": "center",
                                                      "padding-top": "15px",
                                                      "font-size": "16px",
                                                      "line-height": "26px"
                                                     })
        $(".quality-content-view-more").before($wenkuclone)
        $("#show-answer-hide").click()
    },1000)

    $(".leftup").hide()
    $(".new-icon").hide()
    $(".bannerdown").hide()
    $("#qb-side").hide()
    $(".wgt-ads").hide()
    $(".task-list-button").hide()
    $(".exp-topwld-tip").hide()
    $(".question-number-text-chain").hide()
    $("#answer-bar.exp-answerbtn-yh").append("<style>#answer-bar.exp-answerbtn-yh::after{background:none}</style>");
    $(".wgt-bottom-union").hide()
    $(".line.qb-section").attr("style","display:flex;justify-content:center;align-items:center;");
    $(".aside.fixheight").hide()
    $(".wgt-bottom-ask").remove()
    $("#wgt-ecom-banner").hide()
    $(".grid.qb-side").hide()
    $("#wgt-ecom-related").hide()
    $(".wgt-push-bottom.mod-shadow.last").hide()
    $("#knowledge-answer").hide()

    setInterval((function(){
        $("#footer").attr("style","margin:0px 0px 20px 0px; padding:0px")
    }),1)

})();