fCSDNck

屏蔽百度搜索结果中 CSDN 相关搜索结果

  1. // ==UserScript==
  2. // @name fCSDNck
  3. // @name:zh fCSDNck
  4. // @name:zh-CN fCSDNck
  5. // @name:zh-TW fCSDNck
  6. // @namespace https://github.com/tempestLXC/fCSDNck
  7. // @version 0.0.6
  8. // @description 屏蔽百度搜索结果中 CSDN 相关搜索结果
  9. // @description:zh 屏蔽百度搜索结果中 CSDN 相关搜索结果
  10. // @description:zh-CN 屏蔽百度搜索结果中 CSDN 相关搜索结果
  11. // @description:zh-TW 屏蔽百度搜索结果中 CSDN 相关搜索结果
  12. // @author tempestlxc
  13. // @match *://www.baidu.com/*
  14. // @grant none
  15. // @license MIT
  16. // ==/UserScript==
  17.  
  18. (function() {
  19. 'use strict';
  20. var CSDN = '-(csdn)';
  21. var button = document.createElement('button');
  22. button.id = 'bdIndexButton';
  23. button.className = 'btn self-btn bg s_btn';
  24. button.textContent = 'fCSDNck';
  25. button.style.background = '#e33e33';
  26. button.style.display = 'none';
  27. button.addEventListener('click', clickBotton);
  28.  
  29. function clickBotton() {
  30. var kw = document.getElementById('kw');
  31. if (!isEmpty(kw.value) && !kw.value.includes(CSDN)) {
  32. kw.value = kw.value + ' ' + CSDN;
  33. }
  34. }
  35.  
  36.  
  37. function getTargetElement() {
  38.  
  39. var targetElement = document.getElementById('su');
  40. return targetElement;
  41. }
  42.  
  43. var like_comment = getTargetElement();
  44.  
  45.  
  46. if (!isEmpty(like_comment)) {
  47.  
  48. var span = like_comment.parentElement;
  49.  
  50. span.onmouseover = function() {
  51. button.style.display = 'block';
  52. };
  53.  
  54. span.onmouseout = function() {
  55. button.style.display = 'none';
  56. };
  57.  
  58. span.appendChild(button);
  59. }
  60.  
  61.  
  62. function isEmpty(obj) {
  63. if (typeof obj == 'undefined' || obj == null || obj == '') {
  64. return true;
  65. } else {
  66. return false;
  67. }
  68. }
  69. })();