Block CSDN in Google/Baidu Search

Automatically append "-csdn" to search queries to block CSDN results. Works for Google and Baidu search pages.

  1. // ==UserScript==
  2. // @name Block CSDN in Google/Baidu Search
  3. // @name:zh-CN google百度搜索屏蔽CSDN
  4. // @namespace https://github.com/fanyilun0/greasyfork
  5. // @version 0.1
  6. // @description Automatically append "-csdn" to search queries to block CSDN results. Works for Google and Baidu search pages.
  7. // @description:zh-CN 自动在搜索条件后面增加 -csdn, 以此屏蔽csdn网站信息。只适用于google和百度的搜索页面
  8. // @author fanyilun0
  9. // @match *://www.google.com/search*
  10. // @match *://www.baidu.com/s*
  11. // @match *://www.baidu.com/$
  12. // @grant none
  13. // @license MIT
  14. // @compatible firefox
  15. // @compatible chrome
  16. // ==/UserScript==
  17.  
  18. (function () {
  19. 'use strict';
  20.  
  21. const className = {
  22. baidu: '.s_ipt',
  23. google: 'textarea.gLFyf',
  24. };
  25. const key = window.location.href.indexOf('://www.baidu.com') != -1 ? 'baidu' : 'google';
  26. const wordInput = document.querySelector(className[key]);
  27. console.log('match textarea', wordInput);
  28. if (wordInput) {
  29. wordInput.addEventListener('keydown', function (e) {
  30. if (e.key == 'Enter' && this.value.length > 0 && this.value.indexOf('-csdn') == -1) {
  31. this.value += ' -csdn';
  32. }
  33. });
  34. wordInput.addEventListener('blur', function () {
  35. if (this.value.length > 0 && this.value.indexOf('-csdn') == -1) {
  36. this.value += ' -csdn';
  37. }
  38. });
  39. wordInput.addEventListener('focus', function () {
  40. const index = this.value.indexOf(' -csdn');
  41. if (index != -1) {
  42. this.value = this.value.substring(0, index);
  43. }
  44. });
  45. }
  46. })();

QingJ © 2025

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