CSDN|简书优化

支持手机端和PC端

As of 25. 06. 2021. See the latest version.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         CSDN|简书优化
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  支持手机端和PC端
// @author       MT-戒酒的李白染
// @include        http*://www.csdn.net/*
// @include        http*://bbs.csdn.net/*
// @include        http*://www.jianshu.com/*
// @include        http*://blog.csdn.net/*
// @include        http*://download.csdn.net/*
// @grant        GM_addStyle
// @grant        GM_registerMenuCommand
// @grant        GM_unregisterMenuCommand
// @grant        GM_getValue
// @grant        GM_setValue
// @grant       GM_deleteValue
// @grant       GM_listValues
// @run-at         document-start
// @require	     http://cdn.staticfile.org/jquery/2.1.4/jquery.min.js
// ==/UserScript==

(function() {
    'use strict';
    var GM_menus = [
        ["menu_showRedirect","显示Redirect",true,"111"],
        ["menu_thistab","新页面打开",true,"222"]
    ]

    function change_normal_menu(){
        //修改菜单默认值
        console.log(GM_listValues())
        for(let i=0;i<GM_menus.length;i++){
            let get_GM_value = GM_getValue(GM_menus[i][0]);
            if(get_GM_value){
               
            }else{
                console.log("修改菜单值");
                GM_menus[i][2]=false;
            }
            console.log(GM_menus);
        }
    }
    function register_GM_Menu(){
        //注册油猴菜单
        for(let i=0;i<GM_menus.length;i++){
            let current_v =  GM_menus[i][0];
            let current_name = GM_menus[i][1];
            let current_status = GM_menus[i][2]; 
            GM_registerMenuCommand(`[${current_status?"√":"×"}${current_name}]`,function(){
                if(current_status){
                    console.log("关闭");
                    GM_deleteValue(current_v);
                }else{
                    console.log("开启");
                    GM_setValue(current_v,"1");
                }
                window.location.reload();
            },GM_menus[i][3])
        }

    }
    change_normal_menu();
    register_GM_Menu();
    var usa = navigator.userAgent.match('Windows');

    if(usa !== null)
        {//电脑
            GM_addStyle(`
                .ecommend-item-box.recommend-recommend-box{
                    display:none;
                }
                .blog_container_aside,#nav{
                    margin-left:-45px;
                }
                .recommend-right.align-items-stretch.clearfix,.dl_right_fixed{
                    margin-left:45px;
                }
            `)
            try{localStorage.setItem("anonymousUserLimit", "");}catch(err){}
            try{csdn.copyright.textData="";}catch(err){}
            try{document.querySelector("#mainBox > aside").remove();document.querySelector("#mainBox > main").style="width:1300px;";}catch(err){}
            try{document.querySelector("#btn-readmore-zk").click();}catch(err){}
            try{document.querySelector("body > div.login-mark").style="display:none";}catch(err){}
            try{document.querySelector("#passportbox").style=("display:none");}catch(err){}
            try{document.querySelector("#dmp_ad_58").remove();}catch(err){}
            try{document.querySelector("#writeGuide").remove();}catch(err){}
            try{document.querySelector(".leftPop").remove();}catch(err){}
            try{var a = document.getElementsByClassName("recommend-item-box recommend-recommend-box");var i = 0;for(i=0;i<a.length;i++){a[i].remove();}}catch(err){}
            try{var b = document.getElementsByClassName("recommend-item-box recommend-recommend-box");var j = 0;for(i=0;i<a.length;i++){a[i].remove();}}catch(err){}

        }else
        {//手机
            if(location.href.match(/csdn.net/g)){
                function replace_all_commend(){//替换所有的推荐
                    var commend_list = $(".container-fluid");
                    console.log(commend_list)
                    for(var coml=0;coml<commend_list.length;coml++){
                        let current_commend_className = commend_list[coml].getAttribute("class");
                        let current_commend_url="";
                        let current_commend_title = "";
                        let current_commend_content = "";
                        let current_commend_img = "";
                        console.log(current_commend_className)
                        if(commend_list[coml].getAttribute("data-url")){
                            //有data-url 就有recommend_title
                            console.log("有 data-url");
                            current_commend_url= commend_list[coml].getAttribute("data-url");
                            current_commend_title = $(commend_list[coml]).find(".recommend_title").html();
                            current_commend_content = $(commend_list[coml]).find(".text").html();
                            // current_commend_title = commend_list[coml].getElementsByClassName("recommend_title")[0].innerHTML;
                            // current_commend_content = commend_list[coml].getElementsByClassName("text active")[0].innerHTML;
                            let current_commend_img_dom = $(commend_list[coml]).find(".recommend-img");
                            if(current_commend_img_dom.length){
                                for(var imgs = 0;imgs<current_commend_img_dom.length;imgs++){
                                    current_commend_img = current_commend_img+current_commend_img_dom[imgs].innerHTML;
                                } 
                            } 
                            

                        }else{
                            console.log("没有data-url");
                            current_commend_url = commend_list[coml].getElementsByTagName("a")[0].href;
                            current_commend_title = commend_list[coml].getElementsByTagName("a")[0].innerHTML;
                            current_commend_content =  commend_list[coml].getElementsByClassName("text")[0].innerHTML;
                            current_commend_img =  "";
                        }
                        console.log("真实url:",current_commend_url);
                        if(GM_menus[0][2]){
                            current_commend_title = current_commend_title +`<div class="GM-csdn-Redirect">Redirect</div>`;
                        }
                        
                        commend_list[coml].className="GM-csdn-dl";
                        commend_list[coml].setAttribute("data-url",current_commend_url);
                        commend_list[coml].innerHTML = 
                        `<div class="GM-csdn-title">`+current_commend_title+"</div>"+
                        `<div class="GM-csdn-content">`+current_commend_content+"</div>"+
                        `<div class="GM-csdn-img">`+current_commend_img+"</div>"
                        $("#recommend").find(".recommend_list").before($("#first_recommend_list").find("dl").parent().html())
                        $("#first_recommend_list").remove();

                    }
                }
                function new_commend_event(){//新的推荐跳转事件
                    $(".GM-csdn-dl").bind("click",function(e){
                        let current_click_url = e.currentTarget.dataset.url;
                        if(GM_menus[1][2]){
                            window.open(current_click_url);
                        }else{
                            window.location.href=current_click_url;
                        }
                        
                    })
                }
                GM_addStyle(`
                            #mainBox {
                                      width: auto;
                            }
                            #operate,.feed-Sign-span,.view_comment_box, .weixin-shadowbox.wap-shadowbox{
                                      display:none !important;
                            }
                            .GM-csdn-dl{
    padding: .24rem .32rem;
    width: 100%;
    justify-content: space-between;
    -webkit-box-pack: justify;
    border-bottom: 1px solid #F5F6F7!important;

                            }
                            .GM-csdn-title{
                                font-size: .3rem;
    color: #222226;
    letter-spacing: 0;
    line-height: .44rem;
    font-weight: 600;
    //max-height: .88rem;
    word-break: break-all;
    overflow: hidden;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2
                            }
                            .GM-csdn-title a{
                            word-break: break-all;
    color: #222226;
    font-weight: 600;
                            }
                            .GM-csdn-title em,.GM-csdn-content em{
    font-style: normal;
    color: #fc5531
                            }
                            .GM-csdn-content{

                                //max-width: 5.58rem;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    color: #555666;
    font-size: .24rem;
    line-height: .34rem;
    max-height: .34rem;
    word-break: break-all;
    -webkit-box-flex: 1;
    -ms-flex: 1;
    flex: 1;
    margin-top: .16rem;

                            }
                            .GM-csdn-img img{
    width: 2.18rem;
    height: 1.58rem;
    //margin-left: .16rem
                            }
                            .GM-csdn-Redirect{
                                color: #555;
                                background-color: #fcfcfc;
                                font-family: sans-serif;
                                margin: auto 2px;
                                border: 2px solid #ccc;
                                border-radius: 4px;
                                padding: 2px 3px;
                                font-size: xx-small;
                                display: inline;
                            }

                `)
                
                $(document).ready(function(){
                    console.log("mobile csdn");
                    try{document.querySelector("#article > div.readall_box > div.btn_mod > a > span").click();}catch(err){}//展开全文
                    try{document.querySelector("#new_read_more").click();}catch(err){}//关闭跳转
                    try{$(".feed-Sign-span")[0].remove()}catch(err){}
                    var loding_comment_dom_num = 0
                    
                    var loding_comment_dom = setInterval(function(){
                        console.log(loding_comment_dom_num)
                        loding_comment_dom_num = loding_comment_dom_num+1;
                        if(loding_comment_dom_num<=5){
                            replace_all_commend();
                            
                        }else{
                            clearInterval(loding_comment_dom);
                            new_commend_event();
                        }
                    },500)
                    
                    
                });
            }else if(location.href.match(/jianshu.com/g)){
                for(var i=0;i<2;i++){
                    console.log("简书");
                    setTimeout(function(){
                        try{document.querySelector("#jianshu-header").remove()}catch(err){}
                        try{document.querySelector("#layout-default > div.main-view > button").remove()}catch(err){}
                        try{document.querySelector("#note-show > div.note > div.content > div > div.collapse-tips > button").click()}catch(err){}
                        try{document.querySelector("#layout-default > div.main-view > div.dialog-1f6iY_0 > div > div > div > div > button.cancel").click()}catch(err){}
                        try{document.querySelector("#note-show > div.note > div:nth-child(5)").remove()}catch(err){}
                        try{var a = document.createElement("style");a.innerHTML="#recommended-notes {display:none}";document.head.appendChild(a)}catch(err){}
                        try{document.querySelector("#footer").remove()}catch(err){}
                    },0)
                }
            }
        }



})();