完美格式打印CSDN博客内容

平时经常从CSDN打印博客看,发现一般JS打印CSDN博客,出现右边文字显示不全,阅读效果较差。

我在参考了爪洼洼的《打印CSDN网页内容》中JS代码基础上增加了页面样式调整,将整个页面内容调整到一个合适的范围打印。

写下这个内容主要是方便以后,自己打印需要。

具体如下:

打印CSDN博文内容,将以下js复制放入Chrome开发者选项里边的console,回车即可。

    (function(){

    $("#side").remove();

    $("#comment_title, #comment_list, #comment_bar, #comment_form, .announce, #ad_cen, #ad_bot").remove();

    $(".nav_top_2011, #header, #navigator").remove();

    $(".csdn-side-toolbar,.template-box,.reward-user-box").remove();

    $(".p4course_target, .comment-box, .recommend-box, #csdn-toolbar, #tool-box,#dmp_ad_58").remove();

    $("aside").remove();

    $(".tool-box").remove();

    $("main").css('display','content');

    $("main").css('float','left');

    $("#mainBox").css('width','1048px');

    $("#mainBox").css('margin-left','0px');

    $("#mainBox").css('margin-right','0px');

    //$("[class='main_father clearfix d-flex justify-content-center']").css("width","1048px");

    $(".main_father.clearfix.d-flex.justify-content-center").css("width","1048px");

    window.print();

    $("tool-box").remove();

    })();

但是仍有一个问题没有解决就是如下:

对于较长的博客,仍然需要手动点击“展开阅读全文”。

————————————————

版权声明:本文为CSDN博主「qingyunyuy」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。

原文链接:https://blog.csdn.net/qingyunyuy/java/article/details/102777801

你可能感兴趣的:(完美格式打印CSDN博客内容)