Fuck CSDN

在搜索结果中屏蔽 CSDN。支持 Google / Baidu / Bing / 360 搜索

  1. // ==UserScript==
  2. // @name Fuck CSDN
  3. // @namespace Alex3236
  4. // @version 2.1
  5. // @icon https://www.google.com/s2/favicons?sz=64&domain=csdn.net
  6. // @description 在搜索结果中屏蔽 CSDN。支持 Google / Baidu / Bing / 360 搜索
  7. // @license GNU-GPLv3
  8. // @include *://*.baidu.com/s?*
  9. // @include *://*.google.*/search*
  10. // @include *://*.bing.com/search*
  11. // @include *://*.so.com/s*
  12. // @include *://*.csdn.net/*
  13. // @grant none
  14. // ==/UserScript==
  15.  
  16. function isSite(domain) {
  17. return window.location.href.match(new RegExp("^https?:\/\/[\\w.]+?" + domain))
  18. }
  19.  
  20. function HideCSDN(){
  21. const filters = ".source_1Vdff, .iUh30, .b_attribution, .g-linkinfo-a".split(", ")
  22. const Elements=document.querySelectorAll(".result.c-container, .g, .b_algo, .res-list");
  23. let num;
  24. Elements.forEach(function(Item,i){
  25. for (var filter in filters) {
  26. let selectedContent=Item.querySelector(filters[filter])
  27. if (selectedContent !== null) {
  28. if (selectedContent.innerText.toLowerCase().includes("csdn")) {
  29. Item.parentNode.removeChild(Item);
  30. num = i;
  31. break;
  32. }
  33. }
  34. }
  35. });
  36. if (num !== undefined) {
  37. console.log(`[Fuck CSDN] 已去除 ${num} CSDN 内容`)
  38. }
  39. }
  40.  
  41. function bind() {
  42. document.querySelectorAll(".page-item_M4MDr, #form, #page, .ac_wrap").forEach(
  43. function(Item) {
  44. Item.addEventListener('mousedown',function () {
  45. setTimeout(function(){
  46. HideCSDN();
  47. if (isSite('so.com')) {
  48. bind();
  49. }
  50. },1000);
  51. })
  52. }
  53. )}
  54.  
  55. // 绑定回车事件
  56. document.querySelectorAll("input.gLFyf.gsfi, input#kw, input#keyword").forEach(
  57. function(Item) {
  58. Item.addEventListener('keydown', function () {
  59. var evt = window.event || arguments.callee.caller.arguments[0];
  60. if (evt.keyCode == "13") {
  61. setTimeout(function(){HideCSDN();},1000);
  62. }
  63. })})
  64.  
  65. if (isSite('csdn.net')) {
  66. document.body.innerHTML = "Blocked by Fuck CSDN.";
  67. window.history.go(-1);
  68. }
  69.  
  70. HideCSDN();
  71. bind();