EasyCSDN

这是一款促进CSDN极致简洁和高效的插件。免费共享大量创新功能,如:净化页面、展示全屏、显示推荐、复制文本、展开代码等。让我们的学习体验无比简洁、专注、高效、畅快。

As of 2023-12-07. See the latest version.

  1. // ==UserScript==
  2. // @name EasyCSDN
  3. // @description 这是一款促进CSDN极致简洁和高效的插件。免费共享大量创新功能,如:净化页面、展示全屏、显示推荐、复制文本、展开代码等。让我们的学习体验无比简洁、专注、高效、畅快。
  4. // @version 23.0
  5. // @author xcanwin
  6. // @namespace https://github.com/xcanwin/EasyCSDN/
  7. // @supportURL https://github.com/xcanwin/EasyCSDN/
  8. // @license GPL-2.0-only
  9. // @match *://blog.csdn.net/*/article/details/*
  10. // @match *://*.blog.csdn.net/article/details/*
  11. // @grant GM_addStyle
  12. // @run-at document-start
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. const $ = (Selector, el) => (el || document).querySelector(Selector);
  19. const $$ = (Selector, el) => (el || document).querySelectorAll(Selector);
  20.  
  21. /*电脑端净化样式*/
  22. const purify_style_pc = `
  23. .passport-login-container /*隐藏[置顶的]登录提示*/,
  24. .passport-login-tip-container /*隐藏[置顶的]登录权益提示*/,
  25. body>#toolbarBox /*隐藏[置顶的][顶部的]菜单栏*/,
  26. .left-toolbox /*隐藏[置顶的][底部的]关注栏*/,
  27. .blog_container_aside /*隐藏[左边的]栏*/,
  28. #rightAside /*隐藏[右边的]栏*/,
  29. .csdn-side-toolbar /*隐藏[右边的]磁吸栏*/,
  30. .blog-footer-bottom /*隐藏[底部的]网站介绍*/,
  31. .recommend-nps-box /*隐藏[底部的]打分*/,
  32. .blog-tags-box /*隐藏[正文的][顶部的]分类*/,
  33. .column-group /*隐藏[正文的][顶部的]加入社区*/,
  34. #blogColumnPayAdvert /*隐藏[正文的][顶部的]专栏*/,
  35. .more-toolbox-new /*隐藏[正文的][底部的]关注栏*/,
  36. #treeSkill /*隐藏[正文的][底部的]技能树*/,
  37. .recommend-box /*隐藏[正文的][底部的]推荐文章*/,
  38. .hljs-button.signin /*隐藏[正文的][代码块的]复制提示*/,
  39. .article-search-tip /*隐藏[正文的]搜索提示*/
  40. {
  41. display: none !important;
  42. }
  43.  
  44. /*隐藏背景*/
  45. body {
  46. background: none !important;
  47. background-image: unset !important;
  48. background-color: unset !important;
  49. }
  50.  
  51. /*标题居中增大*/
  52. #articleContentId {
  53. display: flex;
  54. justify-content: center;
  55. font-size: 33px;
  56. padding-top:10px;
  57. padding-bottom: 10px;
  58. }
  59.  
  60. /*正文的div居中*/
  61. #mainBox {
  62. display: flex;
  63. justify-content: center;
  64. }
  65.  
  66. /*展示全屏*/
  67. #mainBox {
  68. width: 100%;
  69. }
  70. #mainBox main {
  71. width: 95%;
  72. margin-bottom: unset !important;
  73. }
  74. .main_father {
  75. padding: unset !important;
  76. }
  77. .main_father.d-flex {
  78. display: unset !important;
  79. }
  80.  
  81. /*临时显示*/
  82. .show-temp {
  83. display: unset !important;
  84. }
  85.  
  86. /*适当展示图片*/
  87. img {
  88. max-width: 70% !important;
  89. }
  90.  
  91. /*阅读全文*/
  92. .hide-article-box {
  93. display: none !important;
  94. }
  95. #article_content {
  96. height: auto !important;
  97. overflow: auto !important;
  98. }
  99. `;
  100.  
  101.  
  102. /*移动端净化样式*/
  103. const purify_style_mb = `
  104. #csdn-toolbar /*隐藏[置顶的][顶部的]菜单栏*/,
  105. #operate /*隐藏[置顶的][底部的]搜索标签与评论*/,
  106. .aside-header-fixed /*隐藏[顶部的]关注*/
  107. {
  108. display: none !important;
  109. }
  110.  
  111. /*展示全屏*/
  112. body #main {
  113. padding-top: unset !important;
  114. margin-top: unset !important;
  115. }
  116. body {
  117. padding-bottom: unset !important;
  118. }
  119.  
  120. /*展示分界线*/
  121. .spec_space {
  122. background-color: #ffebeb !important;
  123. height: 32px !important;
  124. }
  125. `;
  126.  
  127. //净化页面
  128. const purifyPage = function() {
  129. GM_addStyle(purify_style_pc);
  130. GM_addStyle(purify_style_mb);
  131. };
  132.  
  133. //显示推荐的开关
  134. const showRecommend = function() {
  135. const sr = document.createElement("div");
  136. sr.style = "height: 64px; background-color: #eaeaea;";
  137. sr.onclick = function() {
  138. $$(".recommend-box").forEach(el => {
  139. el.classList.toggle("show-temp");
  140. });
  141. $(".recommend-box")?.scrollIntoView();
  142. };
  143. $('main').insertBefore(sr, $('.recommend-box'));
  144. };
  145.  
  146. //展开代码
  147. const prettyCode = function() {
  148. const browser_menu_height = window.outerHeight - window.innerHeight; //浏览器顶部菜单栏高度
  149. const browser_height_max = screen.height - browser_menu_height; //浏览器最大可展示高度
  150. let i = 0;
  151. $$('.set-code-hide').forEach(el => {
  152. if (i == 0 && $("code", el)?.clientHeight <= browser_height_max * 1.8) {
  153. //预判首个代码块实际高度,若小于浏览器最大可展示高度的180%,则自动展开代码
  154. $(".hide-preCode-bt", el)?.click();
  155. } else if ($("code", el)?.clientHeight <= browser_height_max * 0.8) {
  156. //预判其余代码块实际高度,若小于浏览器最大可展示高度的80%,则自动展开代码
  157. $(".hide-preCode-bt", el)?.click();
  158. }
  159. i++;
  160. });
  161. };
  162.  
  163. //拦截推荐搜索
  164. const hookXHR = function() {
  165. const origOpen = XMLHttpRequest.prototype.open;
  166. const block_url = 'redisdatarecall\.csdn\.net/recommend/';
  167. XMLHttpRequest.prototype.open = function() {
  168. console.log('request started!');
  169. const reqUrl = arguments[1];
  170. if (reqUrl.match(block_url)){
  171. return;
  172. }
  173. origOpen.apply(this, arguments);
  174. };
  175. };
  176.  
  177. window.onload = function() {
  178. showRecommend();
  179. prettyCode();
  180. };
  181.  
  182. purifyPage();
  183. hookXHR();
  184.  
  185. })();