Greasy Fork is available in English.

把Google搜索伪装成百度搜索

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

2020-06-11 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

  1. // ==UserScript==
  2. // @name 把Google搜索伪装成百度搜索
  3. // @namespace win.somereason.web.utils
  4. // @version 2020.6.10.1
  5. // @description 用Google搜索,很多人看到屏幕后会问你怎么上Google的.所以当我们把Google的logo换成百度,他们就不会问那么多问题了!
  6. // @author somereason
  7. // @license MIT
  8. // @date 2018-10-05
  9. // @include *://www.google.com/search*
  10. // @include *://www.google.com.*/search*
  11. // @include *://www.google.com/
  12. // @include *://www.google.com.*/
  13. // @grant none
  14. // ==/UserScript==
  15. //
  16.  
  17.  
  18. (function () {
  19. //伪装favicon
  20. var link = document.querySelector("link[rel*='icon']") || document.createElement('link');
  21. link.type = 'image/x-icon';
  22. link.rel = 'shortcut icon';
  23. link.href = 'https://www.baidu.com/favicon.ico';
  24. document.getElementsByTagName('head')[0].appendChild(link);
  25. //搜索页
  26. if(window.location.href.indexOf("/search")>-1){
  27. //伪装搜索结果页面logo
  28. var logo = document.getElementById("logo");
  29. var logoArr;
  30. //应对样式的变更,尝试用不同方式获取logo
  31. if (logo === null) {
  32. logoArr = document.getElementsByClassName("logo");
  33. if (logoArr.length > 0)
  34. logo = logoArr[0];
  35. }
  36. if (logo === null) {
  37. logoArr = document.getElementsByClassName("logocont");
  38. if (logoArr.length > 0)
  39. logo = logoArr[0];
  40. }
  41. if (logo === null) { //logo获取失败
  42. console.log("oops,google又改样式了.请静待更新");
  43. } else {
  44. var imgSize = getImgSize(logo);
  45. 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>';
  46. document.title = document.title.replace(/\s-\sGoogle\s搜(索|尋)/g, " - 百度搜索"); //支持繁体,谢谢david082321提醒
  47. }
  48.  
  49. //下面的翻页改成百度的脚丫子
  50. var navTabSpans = document.getElementsByClassName("SJajHc");
  51. for(var i=0;i<navTabSpans.length;i++){
  52. var naviImageUrl="https://ss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K/r/www/cache/static/protocol/https/global/img/icons_5859e57.png";
  53. navTabSpans[i].style.width="22px";
  54. if(i===0) //开始的大G
  55. navTabSpans[i].style.background='url("'+naviImageUrl+'") no-repeat 0px 0px';
  56. else if(navTabSpans[i].classList.contains("NVbCr")){// 变灰色的导航页
  57. navTabSpans[i].style.background= i%2==1?'url("'+naviImageUrl+'") no-repeat -144px -288px':'url("'+naviImageUrl+'") no-repeat -144px -282px'; //让页面底部的百度脚丫子错落有致,感谢Raka-loah
  58. }
  59. else //当前导航页
  60. navTabSpans[i].style.background='url("'+naviImageUrl+'") no-repeat -96px -288px';
  61. }
  62. }else{//首页
  63. let bannerLogo=document.getElementById("lga").getElementsByTagName("img")[0]; //原来变量名hplogo和Google重复,导致图片操作失效...干...
  64. bannerLogo.src="//www.baidu.com/img/bd_logo1.png";
  65. bannerLogo.removeAttribute("srcset");
  66. bannerLogo.width=270;
  67. bannerLogo.height=129;
  68. //修改paddingtop的设置方式,改为原值-20px.避免硬性设置.造成不同浏览器下位置错乱.
  69. let paddingTop=bannerLogo.style.paddingTop.replace("px","");
  70. let paddingTopInt=parseInt(paddingTop);
  71. bannerLogo.style.paddingTop=(paddingTopInt-20)+"px";
  72. var searchBtns=document.getElementsByName("btnK");
  73. for(var x=0;x<searchBtns.length;x++){
  74. searchBtns[x].value=searchBtns[x].value.replace(/Google\s?/,"百度");
  75. }
  76. document.title = document.title.replace(/Google/g, "百度一下,你就知道");
  77. //按钮下语言切换的提示 arnes提供
  78. var footnote=document.getElementById("SIvCob");
  79. if(footnote!==null) //某些ip下,可能没有SIvCob,谢谢BeefOnionDumplings提醒.
  80. footnote.innerHTML=footnote.innerHTML.replace(/Google\s?/,"百度");
  81. //底部的google
  82. var footElements=document.getElementsByClassName("Fx4vi");
  83. for(var u=0;u<footElements.length;u++){
  84. footElements[u].innerHTML=footElements[u].innerHTML.replace(/Google\s?/,"百度");
  85. }
  86.  
  87. }
  88. /**
  89. * 获取图片的大小
  90. * @param elLogo
  91. */
  92. function getImgSize(elLogo) {
  93. var elImg = elLogo.querySelector("img");
  94. if (elImg === null) {
  95. return {height: 30, width: 92}
  96. } else {
  97. return {height: elImg.height, width: elImg.width}
  98. }
  99. }
  100. })();