把Google搜索伪装成百度搜索

用Google搜索,很多人看到屏幕后会问你怎么上Google的.所以当我们把Google的logo换成百度,他们就不会问那么多问题了!

Install this script?
Author's suggested script

You may also like 导出京东订单.

Install this script
  1. // ==UserScript==
  2. // @name 把Google搜索伪装成百度搜索
  3. // @namespace win.somereason.web.utils
  4. // @version 2023.3.19
  5. // @description 用Google搜索,很多人看到屏幕后会问你怎么上Google的.所以当我们把Google的logo换成百度,他们就不会问那么多问题了!
  6. // @author somereason
  7. // @license MIT
  8. // @match *://www.google.com/search*
  9. // @match *://www.google.com.*/search*
  10. // @match *://www.google.com/
  11. // @match *://www.google.com.*/
  12. // @icon https://www.baidu.com/favicon.ico
  13. // @grant none
  14. // ==/UserScript==
  15. //
  16.  
  17. function addCSS() {
  18. let css =
  19. ".titleLink {" +
  20. " color: #0000cc !important;" +
  21. "}"
  22. if (typeof GM_addStyle != "undefined") {
  23. GM_addStyle(css);
  24. } else if (typeof PRO_addStyle != "undefined") {
  25. PRO_addStyle(css);
  26. } else if (typeof addStyle != "undefined") {
  27. addStyle(css);
  28. } else {
  29. var node = document.createElement("style");
  30. node.type = "text/css";
  31. node.appendChild(document.createTextNode(css));
  32. var heads = document.getElementsByTagName("head");
  33. if (heads.length > 0) {
  34. heads[0].appendChild(node);
  35. } else {
  36. // no head yet, stick it whereever
  37. document.documentElement.appendChild(node);
  38. }
  39. }
  40. }
  41.  
  42. (function () {
  43. //addCSS()
  44.  
  45.  
  46. //伪装favicon
  47. var link = document.querySelector("link[rel*='icon']") || document.createElement('link');
  48. link.type = 'image/x-icon';
  49. link.rel = 'shortcut icon';
  50. link.href = 'https://www.baidu.com/favicon.ico';
  51. document.getElementsByTagName('head')[0].appendChild(link);
  52.  
  53. //搜索页
  54. if (window.location.href.indexOf("/search") > -1) {
  55. //伪装搜索结果页面logo
  56. var logo = document.getElementById("logo");
  57. var logoArr;
  58. //应对样式的变更,尝试用不同方式获取logo
  59. if (logo === null) {
  60. logoArr = document.getElementsByClassName("logo");
  61. if (logoArr.length > 0)
  62. logo = logoArr[0];
  63. }
  64. if (logo === null) {
  65. logoArr = document.getElementsByClassName("logocont");
  66. if (logoArr.length > 0)
  67. logo = logoArr[0];
  68. }
  69. if (logo === null) { //logo获取失败
  70. console.log("oops,google又改样式了.请静待更新");
  71. } else {
  72. var imgSize = getImgSize(logo);
  73. logo.innerHTML = '<a href="/" data-hveid="7"><img src="https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo_top_86d58ae1.png" alt="Baidu" data-atf="3" height="' + imgSize.height + 'px" width="' + imgSize.width + 'px"></a>';
  74.  
  75. document.title = document.title.replace(/\s-\sGoogle\s(搜(索|尋)|Search)/g, " - 百度搜索"); //支持繁体,谢谢david082321提醒
  76. }
  77.  
  78. //修改为百度的配色, 由于找不到办法覆盖a:visited, 取消
  79. //document.querySelectorAll("a h3").forEach(a => a.className += " titleLink");
  80.  
  81. document.querySelectorAll("span.st").forEach(a => a.style.color = "#333333")
  82. document.querySelectorAll("em, .rbt b, .c b, .fl b").forEach(a => a.style.color = "#CC0000")
  83.  
  84. //下面的翻页改成百度的脚丫子
  85. var navTabSpans = document.getElementsByClassName("SJajHc");
  86. for (var i = 0; i < navTabSpans.length; i++) {
  87. var naviImageUrl = "https://ss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K/r/www/cache/static/protocol/https/global/img/icons_5859e57.png";
  88. navTabSpans[i].style.width = "22px";
  89. if (i === 0) { //开始的大G
  90. navTabSpans[i].style.background = 'url("' + naviImageUrl + '") no-repeat 0px 0px';
  91. } else if (i == navTabSpans.length - 1) {
  92. navTabSpans[i].style.background = 'url("' + naviImageUrl + '") no-repeat 0px 0px';
  93. } else if (navTabSpans[i].classList.contains("NVbCr")) {// 变灰色的导航页
  94. navTabSpans[i].style.background = i % 2 == 1 ? 'url("' + naviImageUrl + '") no-repeat -144px -288px' : 'url("' + naviImageUrl + '") no-repeat -144px -282px'; //让页面底部的百度脚丫子错落有致,感谢Raka-loah
  95. } else { //当前导航页
  96. navTabSpans[i].style.background = 'url("' + naviImageUrl + '") no-repeat -96px -288px';
  97. }
  98. }
  99. } else {//首页
  100. let bannerLogo = document.querySelector("[alt=Google]")
  101. bannerLogo.src = "//www.baidu.com/img/bd_logo1.png";
  102. bannerLogo.removeAttribute("srcset");
  103. bannerLogo.width = 270;
  104. bannerLogo.height = 129;
  105. //修改paddingtop的设置方式,改为原值-20px.避免硬性设置.造成不同浏览器下位置错乱.
  106. let paddingTop = bannerLogo.style.paddingTop.replace("px", "");
  107. let paddingTopInt = parseInt(paddingTop);
  108. bannerLogo.style.paddingTop = (paddingTopInt - 20) + "px";
  109.  
  110. var searchBtns = document.getElementsByName("btnK");
  111. for (var x = 0; x < searchBtns.length; x++) {
  112. searchBtns[x].value = searchBtns[x].value.replace(/Google\s?/, "百度");
  113. }
  114.  
  115. document.title = document.title.replace(/Google/g, "百度一下,你就知道");
  116. //按钮下语言切换的提示 arnes提供
  117. var footnote = document.getElementById("SIvCob");
  118. if (footnote !== null) //某些ip下,可能没有SIvCob,谢谢BeefOnionDumplings提醒.
  119. footnote.innerHTML = footnote.innerHTML.replace(/Google\s?/, "百度");
  120. //底部的google
  121. var footElements = document.getElementsByClassName("Fx4vi");
  122. for (var u = 0; u < footElements.length; u++) {
  123. footElements[u].innerHTML = footElements[u].innerHTML.replace(/Google\s?/, "百度");
  124. }
  125.  
  126. }
  127.  
  128.  
  129. /**
  130. * 获取图片的大小
  131. * @param elLogo
  132. */
  133. function getImgSize(elLogo) {
  134. var elImg = elLogo.querySelector("img");
  135. if (elImg === null) {
  136. return {height: 30, width: 92}
  137. } else {
  138. return {height: elImg.height, width: elImg.width}
  139. }
  140. }
  141. })();