Google & Bing 屏蔽CSDN搜索结果

屏蔽CSDN搜索结果

  1. // ==UserScript==
  2. // @name Google & Bing 屏蔽CSDN搜索结果
  3. // @license MIT
  4. // @namespace http://tampermonkey.net/
  5. // @version 1.2
  6. // @description 屏蔽CSDN搜索结果
  7. // @author YourName
  8. // @match *://www.google.com/search*
  9. // @match *://www.google.com.hk/search*
  10. // @match *://www.bing.com/search*
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. // 定义屏蔽规则(支持正则匹配)
  18. const blockList = [
  19. /csdn\.net/i, // 屏蔽CSDN
  20. /csdnimg\.cn/i,
  21. /cloud\.baidu\.com/i,
  22. // 可追加其他网站,如:/jianshu\.com/i
  23. ];
  24. // 定义选择器:每个引擎对应一个数组
  25. const selectors = {
  26. google: ['.g'],
  27. bing: ['.b_ans ','.b_algo', '.b_wpt_bl','.slide'],
  28. baidu: ['.result'],
  29. };
  30.  
  31. // 检测当前搜索引擎
  32. const host = window.location.hostname;
  33. let engine = '';
  34. if (host.includes('google')) engine = 'google';
  35. else if (host.includes('bing')) engine = 'bing';
  36. else if (host.includes('baidu')) engine = 'baidu';
  37.  
  38. // 隐藏匹配的搜索结果
  39. const hideCSDN = () => {
  40. if (!selectors[engine]) return;
  41. const queryStr = selectors[engine].join(', ');
  42. const items = document.querySelectorAll(queryStr);
  43. items.forEach(item => {
  44. let link = '';
  45. if (engine === 'bing') {
  46. // Bing 特殊处理 .b_wpt_bl,链接可能在 cite 或 a 标签中
  47. link = item.querySelector('cite')?.innerText || item.querySelector('a')?.href || '';
  48. } else {
  49. link = item.querySelector('a')?.href || '';
  50. }
  51. if (blockList.some(regex => regex.test(link))) {
  52. item.remove();
  53. }
  54. });
  55. };
  56.  
  57. // 监听页面变化(应对无限滚动加载)
  58. new MutationObserver(hideCSDN).observe(
  59. document.body,
  60. { childList: true, subtree: true }
  61. );
  62.  
  63. // 初始执行
  64. hideCSDN();
  65. })();

QingJ © 2025

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