EasyCSDN

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

Ekde 2023/12/09. Vidu La ĝisdata versio.

  1. // ==UserScript==
  2. // @name EasyCSDN
  3. // @description 这是一款促进CSDN极致简洁和高效的插件。免费共享大量创新功能,如:净化页面、展示全屏、显示推荐、复制文本、展开代码等。让我们的学习体验无比简洁、专注、高效、畅快。
  4. // @version 28.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. .code-annotation /*隐藏[正文的][代码块的]一键注释*/,
  40. .article-search-tip /*隐藏[正文的]搜索提示*/
  41. {
  42. display: none !important;
  43. }
  44.  
  45. /*隐藏背景*/
  46. body {
  47. background: none !important;
  48. background-image: unset !important;
  49. background-color: unset !important;
  50. }
  51.  
  52. /*调整标题*/
  53. #articleContentId {
  54. display: flex;
  55. justify-content: center;
  56. font-size: 33px;
  57. padding-top:23px;
  58. padding-bottom: 10px;
  59. }
  60.  
  61. /*调整头像*/
  62. .article-type-img {
  63. display: none !important;
  64. border-radius: 4px !important;
  65. height: 28px !important;
  66. width: 28px !important;
  67. margin: 6px !important;
  68. margin-right: 20px !important;
  69. }
  70.  
  71. /*正文的div居中*/
  72. #mainBox {
  73. display: flex;
  74. justify-content: center;
  75. }
  76.  
  77. /*正文的图片居中*/
  78. #content_views p img {
  79. display: flex;
  80. margin-left: auto;
  81. margin-right: auto;
  82. }
  83.  
  84. /*展示全屏*/
  85. #mainBox {
  86. width: 100%;
  87. }
  88. #mainBox main {
  89. width: 82%;
  90. margin-bottom: unset !important;
  91. }
  92. .main_father {
  93. padding: unset !important;
  94. }
  95. .main_father.d-flex {
  96. display: unset !important;
  97. }
  98.  
  99. /*临时显示*/
  100. .show-temp {
  101. display: unset !important;
  102. }
  103.  
  104. /*适当展示图片*/
  105. img {
  106. max-width: 70% !important;
  107. }
  108.  
  109. /*阅读全文*/
  110. .hide-article-box {
  111. display: none !important;
  112. }
  113. #article_content {
  114. height: auto !important;
  115. overflow: auto !important;
  116. }
  117. `;
  118.  
  119.  
  120. /*移动端净化样式*/
  121. const purify_style_mb = `
  122. #csdn-toolbar /*隐藏[置顶的][顶部的]菜单栏*/,
  123. #operate /*隐藏[置顶的][底部的]搜索标签与评论*/,
  124. .aside-header-fixed /*隐藏[顶部的]关注*/
  125. {
  126. display: none !important;
  127. }
  128.  
  129. /*展示全屏*/
  130. body #main {
  131. padding-top: unset !important;
  132. margin-top: unset !important;
  133. }
  134. body {
  135. padding-bottom: unset !important;
  136. }
  137.  
  138. /*展示分界线*/
  139. .spec_space {
  140. background-color: #ffebeb !important;
  141. height: 32px !important;
  142. }
  143. `;
  144.  
  145. //净化页面
  146. const purifyPage = function() {
  147. GM_addStyle(purify_style_pc);
  148. GM_addStyle(purify_style_mb);
  149. };
  150.  
  151. //显示推荐的开关
  152. const showRecommend = function() {
  153. const sr = document.createElement("div");
  154. sr.style = "height: 64px; background-color: #eaeaea;";
  155. sr.onclick = function() {
  156. $$(".recommend-box").forEach(el => {
  157. el.classList.toggle("show-temp");
  158. });
  159. $(".recommend-box")?.scrollIntoView();
  160. };
  161. $('main').insertBefore(sr, $('.recommend-box'));
  162. };
  163.  
  164. //展开代码
  165. const prettyCode = function() {
  166. const browser_menu_height = window.outerHeight - window.innerHeight; //浏览器顶部菜单栏高度
  167. const browser_height_max = screen.height - browser_menu_height; //浏览器最大可展示高度
  168. let i = 0;
  169. $$('.set-code-hide').forEach(el => {
  170. if (i == 0 && $("code", el)?.clientHeight <= browser_height_max * 1.8) {
  171. //预判首个代码块实际高度,若小于浏览器最大可展示高度的180%,则自动展开代码
  172. $(".hide-preCode-bt", el)?.click();
  173. } else if ($("code", el)?.clientHeight <= browser_height_max * 0.8) {
  174. //预判其余代码块实际高度,若小于浏览器最大可展示高度的80%,则自动展开代码
  175. $(".hide-preCode-bt", el)?.click();
  176. }
  177. i++;
  178. });
  179. };
  180.  
  181. //拦截推荐搜索
  182. const hookXHR = function() {
  183. const origOpen = XMLHttpRequest.prototype.open;
  184. const block_url = 'redisdatarecall\.csdn\.net/recommend/';
  185. XMLHttpRequest.prototype.open = function() {
  186. const reqUrl = arguments[1];
  187. if (reqUrl.match(block_url)){
  188. return;
  189. }
  190. origOpen.apply(this, arguments);
  191. };
  192. };
  193.  
  194. //调整头像
  195. const beautyLOGO = function() {
  196. $('.article-type-img').src = $('link[rel="shortcut icon"]').href;
  197. $('.article-type-img').style = 'display: block !important;';
  198. };
  199.  
  200. window.onload = function() {
  201. beautyLOGO();
  202. prettyCode();
  203. showRecommend();
  204. };
  205.  
  206. purifyPage();
  207. hookXHR();
  208.  
  209. })();