隐藏百度首页昵称

2022/6/5 12:16:12

  1. // ==UserScript==
  2. // @name 隐藏百度首页昵称
  3. // @namespace hbybyyang
  4. // @match https://www.baidu.com/
  5. // @match https://www.baidu.com/s
  6. // @grant none
  7. // @version 1.5
  8. // @license MIT
  9. // @description 2022/6/5 12:16:12
  10. // ==/UserScript==
  11.  
  12. var Y = function (s) {
  13. return s(s);
  14. };
  15.  
  16. var counter = 0;
  17. var counterMax = 100;
  18. var end = false;
  19. var timeOutH = null;
  20.  
  21. var getName = function () {
  22. return document.querySelector(
  23. "#s-top-username > span.user-name.c-font-normal.c-color-t"
  24. );
  25. };
  26. var getName2 = function () {
  27. return document.querySelector("#user > span.s-top-username");
  28. };
  29.  
  30. function setNone(dom) {
  31. dom.style.display = "none";
  32. end = true;
  33. }
  34.  
  35. function main() {
  36. counter = 0;
  37. clearTimeout(timeOutH);
  38. var path = window.location.pathname;
  39. if (path == "/s") {
  40. Y(function (s) {
  41. counter++;
  42. if (counter > counterMax) return;
  43.  
  44. var c = getName2();
  45. if (c != null) setNone(c);
  46. if (end == false)
  47. timeOutH = setTimeout(function () {
  48. s(s);
  49. }, 0);
  50. });
  51. } else {
  52. Y(function (s) {
  53. counter++;
  54. if (counter > counterMax) return;
  55.  
  56. var c = getName();
  57. if (c != null) setNone(c);
  58. if (end == false)
  59. timeOutH = setTimeout(function () {
  60. s(s);
  61. }, 0);
  62. });
  63. }
  64. }
  65. main();
  66.  
  67. // 监听全部ajax请求
  68. // http://blog.ttionya.com/article-1511.html
  69. (function () {
  70. function ajaxEventTrigger(event) {
  71. var ajaxEvent = new CustomEvent(event, { detail: this });
  72. window.dispatchEvent(ajaxEvent);
  73. }
  74.  
  75. var oldXHR = window.XMLHttpRequest;
  76.  
  77. function newXHR() {
  78. var realXHR = new oldXHR();
  79. realXHR.addEventListener(
  80. "abort",
  81. function () {
  82. ajaxEventTrigger.call(this, "ajaxAbort");
  83. },
  84. false
  85. );
  86. realXHR.addEventListener(
  87. "error",
  88. function () {
  89. ajaxEventTrigger.call(this, "ajaxError");
  90. },
  91. false
  92. );
  93. realXHR.addEventListener(
  94. "load",
  95. function () {
  96. ajaxEventTrigger.call(this, "ajaxLoad");
  97. },
  98. false
  99. );
  100. realXHR.addEventListener(
  101. "loadstart",
  102. function () {
  103. ajaxEventTrigger.call(this, "ajaxLoadStart");
  104. },
  105. false
  106. );
  107. realXHR.addEventListener(
  108. "progress",
  109. function () {
  110. ajaxEventTrigger.call(this, "ajaxProgress");
  111. },
  112. false
  113. );
  114. realXHR.addEventListener(
  115. "timeout",
  116. function () {
  117. ajaxEventTrigger.call(this, "ajaxTimeout");
  118. },
  119. false
  120. );
  121. realXHR.addEventListener(
  122. "loadend",
  123. function () {
  124. ajaxEventTrigger.call(this, "ajaxLoadEnd");
  125. },
  126. false
  127. );
  128. realXHR.addEventListener(
  129. "readystatechange",
  130. function () {
  131. ajaxEventTrigger.call(this, "ajaxReadyStateChange");
  132. },
  133. false
  134. );
  135. return realXHR;
  136. }
  137.  
  138. window.XMLHttpRequest = newXHR;
  139. })();
  140.  
  141. window.addEventListener("ajaxReadyStateChange", function (e) {
  142. main();
  143. });

QingJ © 2025

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