CSDN博客优化

CSDN博客优化

CSDN博客官网:https://blog.csdn.net/

快速处理

打开F12,在console中执行下面代码中的任意一行,即可对博客中的内容选中复制。

需要将下面代码中的中文引号换为英文引号(csdn的引号会变为中文的)

$(“style:contains(‘content_views’)”).remove();
document.getElementById(“content_views”).contentEditable = ‘true’;
document.designMode = ‘on’;

// 未登录时,可以鼠标右键“检查”,复制
$("style:contains('content_views')").remove();
document.getElementById("content_views").contentEditable = 'true';
document.designMode = 'on';

浏览器书签脚本

// 适用于 https://blog.csdn.net/xxxxx/article/details/xxxxx
// 以下代码需要压缩为一行,添加在浏览器的书签中(作为网址),点击即可在当前页面执行
// js压缩网站:https://www.bejson.com/jshtml_format/

JavaScript: (function () {
    if (!/blog\.csdn\.net.*article\/details/.test(location.href)) { return; }

    document.title = $("#articleContentId").text();
    let newHref = location.origin + location.pathname;
    if (location.href != newHref) {
        window.history.pushState(null, null, newHref);
    }
    $("style:contains('content_views')").remove();
    document.getElementById("content_views").contentEditable = 'true';
    if (/127477111/.test(newHref)) {
        document.getElementById("content_views").contentEditable = 'inherit';
    }

    // 右侧显示优化
    if ($("#groupfile").size() > 0) {
        // $("#recommend-right > div.kind_person").remove();  // 分类专栏
        $("#recommend-right > #groupfile").siblings().remove();  // 除目录外全部删除
        $("#recommend-right > #groupfile").css("max-height", "none");  // 目录
        let maxHeight = window.innerHeight - 56 - 10;
        $("#recommend-right > #groupfile > .groupfile-div").css("max-height", maxHeight + "px");
        if ($("#fywy-scrollbar").size() == 0) {
            $("#recommend-right > #groupfile .group_item").append('<style id="fywy-scrollbar">#recommend-right>#groupfile .group_item::-webkit-scrollbar {width: 25px}</style>');
        }
    }

    // 文字选中tip
    if ($("#fywy-tip").size() == 0) {
        $("head").append('<style id="fywy-tip">#articleSearchTip {display: none}</style>');
    }

    // 登录弹出框
    if ($("#fywy-login").size() == 0) {
        $("head").append('<style id="fywy-login">.passport-login-container {display: none}</style>');
    }

    // CSDN自带的关键字搜索
    $("#content_views a.hl.hl-1").css({
        "background-image": "none",
        "margin-right": "0px",
        "margin-left": "0px",
        "padding-right": "0px",
        "padding-left": "0px",
    });

    // csdn两种UI风格,markdown_views和htmledit_views
    // 为了方便复制代码,这里隐藏了代码的行号,再次点击即可显示
    try {
        if ($("div.markdown_views").size() > 0) {
            $("ul.pre-numbering").toggle();
            // [...document.querySelectorAll(".has-numbering")].forEach(e => e.onclick = mdcp.copyCode);
            document.querySelectorAll(".has-numbering").forEach(e => e.onclick = mdcp.copyCode);
        } else if ($("div.htmledit_views").size() > 0) {
            $("div.hljs-ln-numbers").toggle();
            // [...document.querySelectorAll(".signin")].forEach(e => e.onclick = mdcp.copyCode);
            document.querySelectorAll(".signin").forEach(e => e.onclick = mdcp.copyCode);
        }
    } catch (error) {
        console.log("修改复制事件错误", error);
    }

    // "关注博主即可阅读全文" 优化
    if ($("div.hide-article-box").size() > 0) {
        $("#article_content").css("height", "auto");
        $("div.hide-article-box").hide();
    }

    // 去除复制时末尾版权声明
    try {
        document.querySelectorAll("*").forEach(item => {
            item.oncopy = function (e) { e.stopPropagation(); }
        });
    } catch (error) {
        console.log("修改版权声明错误", error);
    }

    // 去除广告
    $("ins.adsbygoogle").parents("#recommend-right > div").remove();
    $("ins.adsbygoogle").remove();
    $("#recommendAdBox").remove();
    $("iframe").remove();
    $(".tool-active-list").remove();
    // 去除推荐download
    let arr = [];
    $(".recommend-item-box").each(function () {
        let href = $(this).find("a.tit").attr("href");
        if (!/blog.csdn.net/.test(href)) {
            arr.push($(this));
        }
    });
    arr.forEach((value) => { value.remove(); });

    // 以下是活动型广告,具有时效性
    $(".toolbar-advert").remove();
    $(".csdn-side-toolbar").remove();
    $("#asideNewNps").remove();
    // $(".box-shadow").css("min-height", "auto");
    $(".box-shadow").remove();

})();

压缩为一行

在线压缩网站:https://www.bejson.com/jshtml_format/

JavaScript:(function(){if(!/blog\.csdn\.net.*article\/details/.test(location.href)){return}document.title=$("#articleContentId").text();let newHref=location.origin+location.pathname;if(location.href!=newHref){window.history.pushState(null,null,newHref)}$("style:contains('content_views')").remove();document.getElementById("content_views").contentEditable='true';if(/127477111/.test(newHref)){document.getElementById("content_views").contentEditable='inherit'}if($("#groupfile").size()>0){$("#recommend-right > #groupfile").siblings().remove();$("#recommend-right > #groupfile").css("max-height","none");let maxHeight=window.innerHeight-56-10;$("#recommend-right > #groupfile > .groupfile-div").css("max-height",maxHeight+"px");if($("#fywy-scrollbar").size()==0){$("#recommend-right > #groupfile .group_item").append('<style id="fywy-scrollbar">#recommend-right>#groupfile .group_item::-webkit-scrollbar {width: 25px}</style>')}}if($("#fywy-tip").size()==0){$("head").append('<style id="fywy-tip">#articleSearchTip {display: none}</style>')}if($("#fywy-login").size()==0){$("head").append('<style id="fywy-login">.passport-login-container {display: none}</style>')}$("#content_views a.hl.hl-1").css({"background-image":"none","margin-right":"0px","margin-left":"0px","padding-right":"0px","padding-left":"0px",});try{if($("div.markdown_views").size()>0){$("ul.pre-numbering").toggle();document.querySelectorAll(".has-numbering").forEach(e=>e.onclick=mdcp.copyCode)}else if($("div.htmledit_views").size()>0){$("div.hljs-ln-numbers").toggle();document.querySelectorAll(".signin").forEach(e=>e.onclick=mdcp.copyCode)}}catch(error){console.log("修改复制事件错误",error)}if($("div.hide-article-box").size()>0){$("#article_content").css("height","auto");$("div.hide-article-box").hide()}try{document.querySelectorAll("*").forEach(item=>{item.oncopy=function(e){e.stopPropagation()}})}catch(error){console.log("修改版权声明错误",error)}$("ins.adsbygoogle").parents("#recommend-right > div").remove();$("ins.adsbygoogle").remove();$("#recommendAdBox").remove();$("iframe").remove();$(".tool-active-list").remove();let arr=[];$(".recommend-item-box").each(function(){let href=$(this).find("a.tit").attr("href");if(!/blog.csdn.net/.test(href)){arr.push($(this))}});arr.forEach((value)=>{value.remove()});$(".toolbar-advert").remove();$(".csdn-side-toolbar").remove();$("#asideNewNps").remove();$(".box-shadow").remove()})();

游猴Tampermonkey脚本(待编写)

// TODO:待编写
// ==UserScript==
// @name         csdn优化
// @namespace    http://tampermonkey.net/
// @version      2022.08.22
// @description  作者博客 https://blog.csdn.net/qq_43111676?type=blog
// @author       https://blog.csdn.net/qq_43111676?type=blog
// @match        https://blog.csdn.net/*/article/details/*
// @grant        none
// @require      https://s3.pstatp.com/cdn/expire-1-M/jquery/3.3.1/jquery.min.js
// ==/UserScript==

$(function () {
    if (!/blog\.csdn\.net.*article\/details/.test(location.href)) { return; }

    document.title = $("#articleContentId").text();
    let newHref = location.origin + location.pathname;
    if (location.href != newHref) {
        window.history.pushState(null, null, newHref);
    }
    $("style:contains('content_views')").remove();
    document.getElementById("content_views").contentEditable = 'true';
    if (/127477111/.test(newHref)) {
        document.getElementById("content_views").contentEditable = 'inherit';
    }

    // 右侧显示优化
    if ($("#groupfile").size() > 0) {
        // $("#recommend-right > div.kind_person").remove();  // 分类专栏
        $("#recommend-right > #groupfile").siblings().remove();  // 除目录外全部删除
        $("#recommend-right > #groupfile").css("max-height", "none");  // 目录
        let maxHeight = window.innerHeight - 56 - 10;
        $("#recommend-right > #groupfile > .groupfile-div").css("max-height", maxHeight + "px");
        if ($("#fywy-scrollbar").size() == 0) {
            $("#recommend-right > #groupfile .group_item").append('<style id="fywy-scrollbar">#recommend-right>#groupfile .group_item::-webkit-scrollbar {width: 25px}</style>');
        }
    }

    // 文字选中tip
    if ($("#fywy-tip").size() == 0) {
        $("head").append('<style id="fywy-tip">#articleSearchTip {display: none}</style>');
    }

    // 登录弹出框
    if ($("#fywy-login").size() == 0) {
        $("head").append('<style id="fywy-login">.passport-login-container {display: none}</style>');
    }

    // CSDN自带的关键字搜索
    $("#content_views a.hl.hl-1").css({
        "background-image": "none",
        "margin-right": "0px",
        "margin-left": "0px",
        "padding-right": "0px",
        "padding-left": "0px",
    });

    // csdn两种UI风格,markdown_views和htmledit_views
    // 为了方便复制代码,这里隐藏了代码的行号,再次点击即可显示
    try {
        if ($("div.markdown_views").size() > 0) {
            $("ul.pre-numbering").toggle();
            // [...document.querySelectorAll(".has-numbering")].forEach(e => e.onclick = mdcp.copyCode);
            document.querySelectorAll(".has-numbering").forEach(e => e.onclick = mdcp.copyCode);
        } else if ($("div.htmledit_views").size() > 0) {
            $("div.hljs-ln-numbers").toggle();
            // [...document.querySelectorAll(".signin")].forEach(e => e.onclick = mdcp.copyCode);
            document.querySelectorAll(".signin").forEach(e => e.onclick = mdcp.copyCode);
        }
    } catch (error) {
        console.log("修改复制事件错误", error);
    }

    // "关注博主即可阅读全文" 优化
    if ($("div.hide-article-box").size() > 0) {
        $("#article_content").css("height", "auto");
        $("div.hide-article-box").hide();
    }

    // 去除复制时末尾版权声明
    try {
        document.querySelectorAll("*").forEach(item => {
            item.oncopy = function (e) { e.stopPropagation(); }
        });
    } catch (error) {
        console.log("修改版权声明错误", error);
    }

    // 去除广告
    $("ins.adsbygoogle").parents("#recommend-right > div").remove();
    $("ins.adsbygoogle").remove();
    $("#recommendAdBox").remove();
    $("iframe").remove();
    // 去除推荐download
    let arr = [];
    $(".recommend-item-box").each(function () {
        let href = $(this).find("a.tit").attr("href");
        if (!/blog.csdn.net/.test(href)) {
            arr.push($(this));
        }
    });
    arr.forEach((value) => { value.remove(); });

    // 以下是活动型广告,具有时效性
    $(".toolbar-advert").remove();
    $(".csdn-side-toolbar").remove();
    $("#asideNewNps").remove();
    // $(".box-shadow").css("min-height", "auto");
    $(".box-shadow").remove();

});

作者博客首页:https://blog.csdn.net/qq_43111676?type=blog
欢迎关注,持续更新中…

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值