Google & baidu Switcher (修改版)

基于Google_baidu_Switcher_(ALL_in_One)修改,分别在百度和google的搜索结果页面增加搜索跳转按钮。

  1. // ==UserScript==
  2. // @name Google & baidu Switcher (修改版)
  3. // @namespace http://tampermonkey.net/
  4. // @author ZeroCode
  5. // @version 0.2.2
  6. // @description 基于Google_baidu_Switcher_(ALL_in_One)修改,分别在百度和google的搜索结果页面增加搜索跳转按钮。
  7. // @include https://www.google.*
  8. // @include http://www.google.*
  9. // @include https://ipv6.google.*
  10. // @include http://ipv6.google.*
  11. // @include http://www.baidu.com/*
  12. // @include https://www.baidu.com/*
  13. // @include http://image.baidu.com/*
  14. // @include https://image.baidu.com/*
  15. // @require https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js
  16. // @note 18.12.30-V0.2.2 谷歌搜索按钮优化。
  17. // @note 18.12.11-V0.2.1 搜索按钮显示效果调整。
  18. // @note 18.12.11-V0.2.0 增加百度图片搜索与谷歌图片搜索之间跳转功能。
  19. // @note 18.01.02-V0.1.2 微调百度页面中google搜索按钮,兼容AC-Baidu。
  20. // @note 17.08.22-V0.1.1 微调Google中百度搜索按钮显示效果。
  21. // @note 16.12.23-V0.1.0
  22.  
  23. // ==/UserScript==
  24. (function() {
  25. 'use strict';
  26. if(location.host.indexOf("baidu.com") > -1){
  27. if (getUrlParam("wd").length > 0 || getUrlParam("word").length > 0 || window.location.href.lastIndexOf("/s?") > 0) {
  28. baidu2google();
  29. }
  30. //2018/11/07 F9y4ng 检测从baidu首页进入的搜索(修正自动提交的Bug)
  31. if (/^http(s)?:\/\/(www\.)?baidu\.com\/$/ig.test(window.location.href)) {
  32. $("#kw").on("blur", function () {
  33. if ($('#kw').val().length > 0) {
  34. setTimeout(function () {
  35. if ($('#google_search').length < 1 && getUrlParam("wd").length > 0) {
  36. baidu2hgoogle();
  37. }
  38. }, 600);
  39. }
  40. });
  41. }
  42. }
  43. else if(location.host.indexOf(".google.") > -1){
  44. if (window.location.hash.lastIndexOf("q=") > 0 || window.location.search.lastIndexOf("q=") > 0) {
  45. google2baidu();
  46. }
  47. //2018/11/07 F9y4ng GOOGLE首页自动提交搜索修正
  48. if (/^http(s)?:\/\/(www\.)?google\.\w+(\.\w+)?\/$/ig.test(window.location.href) || getUrlParam("q") === "") {
  49. var gfm = $('input[name="q"]');
  50. if ("undefined" == typeof (gfm)) {
  51. gfm = $("input[role='combobox']");
  52. }
  53. gfm.off('click').on({
  54. blur: function () {
  55. if (gfm.val().length > 0) {
  56. $("form").submit();
  57. }
  58. }
  59. });
  60. }
  61. var ua = myBrowser();
  62. if (ua == "FF" || ua == "Edge") {
  63. $('#bdyxwz').css('margin-top', '10px');
  64. $('#bdyxss').css('margin', '12px 2px 0 4px');
  65. }
  66. else {
  67. $('#bdyxwz').css('margin-top', '0px');
  68. $('#bdyxss').css('margin', '2px 2px 0 4px');
  69. }
  70. var elm = $('#bdyx');
  71. var startPos = $(elm).offset().top;
  72. $.event.add(window, "scroll", function () {
  73. var p = $(window).scrollTop();
  74. $(elm).css('height', ((p) > startPos) ? '37px' : '49px');
  75. if (ua == "FF" || ua == "Edge") {
  76. $('#bdyxwz').css('margin-top', ((p) > startPos) ? '5px' : '10px');
  77. $('#bdyxss').css('margin', ((p) > startPos) ? '7px 2px 0 4px' : '12px 2px 0 4px');
  78. }
  79. });
  80. }
  81. function baidu2google() {
  82. $('.s_btn_wr').after('<div class="bg s_btn_wr" style="margin-left:10px"><input type="button" id="google_search" value="Google一下" class="bg s_btn" ></div>');
  83. var s_url = "https://www.google.com/search?newwindow=1&hl=zh-CN&source=hp";
  84. if(getUrlParam("tn") == "baiduimage") {
  85. s_url = s_url + "&tbm=isch";
  86. }
  87. $('#google_search').on({
  88. click: function () {
  89. window.open(s_url + "&q=" + encodeURIComponent($('#kw').val()));
  90. return false;
  91. }
  92. });
  93. baidu_resize();
  94. $(window).on("resize", function(){
  95. baidu_resize();
  96. });
  97. }
  98. function baidu_resize() {
  99. if($("#result_logo").css("left") != "auto"){
  100. $(".s_ipt_wr").width($(".s_ipt_wr").width() - 70);
  101. }
  102. }
  103. function google2baidu(){
  104. $('#tsf').prepend('<div id="sfdiv_bd" style="display:inline-block;position:relative;height:0px;width:110px;right:-115px;\
  105. top:0px;float:right;"><button id="bdyx" class="lsbb kpbb" style="width:120px;height:49px;margin-top:-2px;cursor:pointer;\
  106. display: flex;border-radius: 8px;border: 1px solid #dfe1e5;box-shadow: none;border-radius: 24px;" type="button"><span \
  107. class="sbico" id="bdyxss" style="color:#fff"><svg focusable="false" style="fill: #fff;" xmlns="https://www.w3.org/2000/svg"\
  108. viewBox="0 0 24 24"><path d="M15.5 14h-.79l-.28-.27A6.471 6.471 0 0 0 16 9.5 6.5 6.5 0 1 0 9.5 16c1.61 0 3.09-.59 \
  109. 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z">\
  110. </path></svg></span><span id="bdyxwz" style="font-size:16px;">百度一下</span></button></div>');
  111. var s_url = "https://www.google.com/search?newwindow=1&hl=zh-CN&source=hp";
  112. $('#sfdiv_bd').off("click").on("click", function(){
  113. var kw = $('input[name="q"]').val();
  114. //获取属性标签容错
  115. if ("undefined" == typeof (kw)) {
  116. kw = getUrlParam("q");
  117. }
  118. var s_url = "https://www.baidu.com/s?ie=utf-8&rqlang=cn";
  119. if(getUrlParam("tbm") == "isch") s_url = "https://image.baidu.com/search/index?tn=baiduimage&ie=utf-8&rqlang=cn";
  120. window.open(s_url + "&wd=" + encodeURIComponent(kw));
  121. return false;
  122. });
  123. }
  124.  
  125. function getUrlParam(name) {
  126. //构造一个含有目标参数的正则表达式对象
  127. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  128. //匹配目标参数
  129. var r = window.location.search.substr(1).match(reg);
  130. //返回参数值
  131. if (r != null) return unescape(r[2]);
  132. return "";
  133. }
  134. })();
  135.  
  136. function myBrowser() {
  137. var userAgent = navigator.userAgent;
  138. if (userAgent.indexOf("Firefox") > -1) {
  139. return "FF";
  140. }
  141. if (userAgent.indexOf("Edge") > -1) {
  142. return "Edge";
  143. }
  144. }

QingJ © 2025

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