Greasy Fork is available in English.

clean CSDN blog

还你一个干净的阅读体验

  1. // ==UserScript==
  2. // @name clean CSDN blog
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1.4
  5. // @description 还你一个干净的阅读体验
  6. // @author Lynxz
  7. // @match *://*.blog.csdn.net
  8. // @match *://*.blog.csdn.net/*
  9. // @match *://bbs.csdn.net/*
  10. // @match *://so.csdn.net/*
  11. // @match *://www.csdn.net
  12. // @match *://www.csdn.net/*
  13. // @match *://download.csdn.net
  14. // @match *://download.csdn.net/*
  15. // @grant none
  16. // ==/UserScript==
  17. // CSDN文章清除博客文章侧边栏和广告元素
  18. // CSDN已自带jquery了,不需要添加此依赖
  19. (function() {
  20. 'use strict';
  21. $('#btn-readmore').click();
  22. // 获取当前地址url
  23. var url = location.href;
  24. // 正则匹配博客部分
  25. var blogcsdn = /blog.csdn.net/i;
  26. if (blogcsdn.test(url)) {
  27. // 页面主体部分轮播广告
  28. $(".box-box-large").remove();
  29. $(".leftPop").remove();
  30. $("#asideProfile").next().remove();
  31. $($("#asideFooter").find("div").first()).remove();
  32. // 隐藏下面登录注册
  33. $(".pulllog-box").remove();
  34. // 首页头部广告
  35. $(".banner-ad-box").remove();
  36. // 去除列表自动加载的广告
  37. $(".recommend-box").bind("DOMNodeInserted", function (e) {
  38. for (var i = 0; i < $(".recommend-ad-box").length; i++) {
  39. // 去除文章列表中间广告
  40. if ($(".recommend-ad-box").attr("class") == "recommend-item-box recommend-ad-box") {
  41. $(".recommend-ad-box").remove();
  42. }
  43. }
  44. });
  45. $($("aside div").first()).remove();
  46. // 右下角弹窗
  47. $("#layerd").remove();
  48. $("#reportContent").remove();
  49. $(".tool-box").remove();
  50. //$("#asideNewComments,.recommend-box,.edu-promotion,.comment-box,aside").remove();
  51. //底部空白
  52. $("main").css("margin-bottom","0px");
  53. //阅读全文
  54. $('#article_content').css("height","");
  55. $("div.readall_box,#btn-readmore,div.hide-article-box.text-center.csdn-tracking-statistics.tracking-click").remove();
  56. //顶部csdn
  57. $("div.csdn-toolbar.csdn-toolbar.tb_disnone").remove();
  58. //底部版权声明
  59. $(".article-copyright").remove();
  60. //上移按钮
  61. $(".meau-gotop-box").remove();
  62. //文章居中
  63. $("main").css("float","none");
  64. $("main").css("margin","auto");
  65. //右下角关闭按钮
  66. $(".box-box-default").remove();
  67. //上部广告
  68. $(".advert-bg").remove();
  69. $(".advert-cur").remove();
  70. $('newsfeed').remove();
  71. //window.addEventListener ("load", removeIframe, false);
  72. //function removeIframe () {
  73. // $('iframe').remove();
  74. //}
  75. // $(".blog-content-box ~ div").remove();//todo:streamline my code
  76. }
  77.  
  78. let bodyWidth = $(document.body).width();
  79. var oriWidth = $('#main').width() || bodyWidth;
  80. // 删除blog页面左侧个人资料等侧边栏
  81. $('#side').remove();
  82. //$(".fl").remove();
  83. // 移除blog内容区域右侧上层互动的二维码和快速回复,我要收藏等元素
  84. // $('.csdn-tracking-statistics:not(.article_content)').remove();
  85. $('.left_fixed').remove();
  86. $('.recommend_list').remove();
  87. $('.pulllog-box').remove();
  88. $('aside').remove();
  89. $('#layerd').remove();
  90. $('#rasss').remove();
  91. // 设置blog内容区域width 100%,填满移除侧边栏后的区域
  92. $('#main').css('padding-left',0);
  93. $('#main').css('width','100%');
  94. $('#main .main').css('padding-left','0px');
  95. $('#main .main').css('margin-left','0px');
  96. $('div.article_content..csdn-tracking-statistics').css('height','100%');
  97. $('#article_content').removeAttr('style');
  98. let curWidth = $('#main').width() || $('#article_content').width();
  99. // 设置文章内容区域的宽度,默认880px,避免阅读时眼球左右转动幅度过大,自行按需调整吧
  100. let w = $('#article_details').width() || oriWidth;
  101. let defaultWidth = 880;
  102. let margin = (w - defaultWidth) / 2 ;
  103. console.log("oriWidth = " + oriWidth + " curWidth = " + curWidth + " w = " + w + " margin = " + margin);
  104. if(margin > 10){
  105. $('.container').width(defaultWidth);
  106. $('main').width(defaultWidth);
  107. $('#article_details').width(defaultWidth);
  108. $('#article_details').css('margin-left', margin +'px');
  109. }
  110. $('.meau-gotop-box').remove();
  111. $('.tool-box').remove();
  112. })();