屏蔽 CSDN

屏蔽 CSDN 及其它垃圾信息

目前为 2024-01-17 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name 屏蔽 CSDN
  3. // @version 1.0
  4. // @author aaron
  5. // @description 屏蔽 CSDN 及其它垃圾信息
  6. // @match https://www.baidu.com
  7. // @match https://www.baidu.com/s*
  8. // @match https://www.google.com
  9. // @match https://www.google.com/search*
  10. // @require https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js
  11. // @grant GM_addStyle
  12. // @grant GM_xmlhttpRequest
  13. // @license MIT
  14. // @namespace https://gf.qytechs.cn/users/1249199
  15. // ==/UserScript==
  16.  
  17. (function () {
  18.  
  19. // 标题
  20. const titleArr = ["CSDN博客","简书","51CTO","博客园", "软件园", "下载之家", "下载网",
  21. "百度健康", "快速问医生", "求医网", "求医问药", "家庭医生","亿速云","动力节点在线","IT 技术博客",
  22. "千锋教育","虎课网","黑马程序员","FinClip","tie.pub","php中文网","mybj123.com","脚本之家","今日头条","慕课网实战课程","群英网络"];
  23.  
  24. // 标题匹配正则
  25. const titleRegex = ["- csdn$"];
  26.  
  27. // 描述
  28. const descArr = ["为您推荐的内容", "阿里云为您提供",];
  29.  
  30. // 屏蔽来源(包含关键字则屏蔽)
  31. const sourceArr = ["博客园", "CSDN博客", "CSDN技术社区", "csdn.net", "百度知道", "腾讯云计算",
  32. "百度文库", "华军软件园", "当下软件园", "东坡下载站",
  33. "系统之家", "软件园", "/soft/", "软件", "下载网", "寻医",
  34. "健康", "健客网", "医生", "柠檬爱美", "紫一商城", "120.net", "求医", "宝宝知道", "58codes.com", "itgh.cn", "frontend.devrank.cn", "codeleading.com", "nzw6.com","悠悠之家","pythonjishu.com","脚本之家","jb51.net"];
  35.  
  36. window.exec = function () {
  37. let contentLeft = document.getElementById("content_left");
  38. let documents = $(contentLeft).find('div[class*="result"]');
  39.  
  40. let googleContentLefts = document.getElementById("center_col");
  41. let googleDocuments = $(googleContentLefts).find('div[class*="MjjYud"]');
  42.  
  43. for (let i = googleDocuments.length - 1; i >= 0; i--) {
  44. isRemove(googleDocuments[i]);
  45. }
  46. };
  47.  
  48. function isRemove(document) {
  49. const title = getTitle(document);
  50. const desc = getDesc(document);
  51. const source = getSource(document);
  52.  
  53. const removeByArray = (text, arr, type) => {
  54. for (const element of arr) {
  55. if (text.includes(element)) {
  56. document.remove();
  57. return;
  58. }
  59. }
  60. };
  61.  
  62. if (title) {
  63. for (const element of titleRegex) {
  64. if (new RegExp(element).test(title)) {
  65. document.remove();
  66. return;
  67. }
  68. }
  69. removeByArray(title, titleArr, 'title');
  70. }
  71.  
  72. if (desc) {
  73. removeByArray(desc, descArr, 'desc');
  74. }
  75.  
  76. if (source) {
  77. removeByArray(source, sourceArr, 'source');
  78. }
  79. }
  80.  
  81. /**
  82. * 获取文章信息
  83. * @param {*} element
  84. * @param {string} selector
  85. * @returns {string}
  86. */
  87. function getArticleInfo(element, selector) {
  88. try {
  89. const selectedElement = element.querySelector(selector);
  90. return selectedElement ? selectedElement.innerText : "";
  91. } catch (error) {
  92. handleError('get error', error);
  93. }
  94. return "";
  95. }
  96.  
  97. /**
  98. * 获取文章标题
  99. * @param {*} element
  100. * @returns {string}
  101. */
  102. function getTitle(element) {
  103. // return getArticleInfo(element, ".t");
  104. return getArticleInfo(element, ".GTRloc");
  105. }
  106.  
  107. /**
  108. * 获取文章描述
  109. * @param {*} element
  110. * @returns {string}
  111. */
  112. function getDesc(element) {
  113. return getArticleInfo(element, 'span[class*="content"]');
  114. }
  115.  
  116. /**
  117. * 获取文章来源
  118. * @param {*} element
  119. * @returns {string}
  120. */
  121. function getSource(element) {
  122. return getArticleInfo(element, 'div[class*="source"]');
  123. }
  124.  
  125. /**
  126. * 通用错误处理函数
  127. * @param {string} message
  128. * @param {Error} error
  129. */
  130. function handleError(message, error) {
  131. console.error(`${message}`, error);
  132. }
  133.  
  134. /**
  135. * 屏蔽内容
  136. */
  137. function hiddenContent() {
  138. let timer;
  139.  
  140. document.body.addEventListener("DOMNodeInserted", (e) => {
  141. if (timer) {
  142. window.clearTimeout(timer);
  143. }
  144. timer = window.setTimeout(() => {
  145. exec();
  146. }, 100);
  147. });
  148. }
  149.  
  150. $(function () {
  151. hiddenContent();
  152. });
  153.  
  154. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址