EasyCSDN

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

2023-12-09 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

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