Google & baidu Switcher (ALL in One)

分别在百度和google的搜索结果页面增加搜索跳转按钮,使用到外链微软CDN的jquery-1.7.2.min.js,不懂跳墙使用GOOGLE的同学请自动忽略。自动判断百度和google对JQUERY的载入,并动态载入Jquery.js。

当前为 2019-05-31 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Google & baidu Switcher (ALL in One)
  3. // @namespace https://openuserjs.org/scripts/t3xtf0rm4tgmail.com/Google_baidu_Switcher_(ALL_in_One)
  4. // @author F9y4ng
  5. // @version 1.5.0.0
  6. // @description 分别在百度和google的搜索结果页面增加搜索跳转按钮,使用到外链微软CDN的jquery-1.7.2.min.js,不懂跳墙使用GOOGLE的同学请自动忽略。自动判断百度和google对JQUERY的载入,并动态载入Jquery.js。
  7. // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAHpSURBVFhH7Ze7SsRAFIYXLSwUaxXEQlEUfQIrWxUsfAk7G2+VYGHnO9j7AjYqaClYWCtWFlp5QfDS6P8lORCGTHZGswnC/vDBzDlz/kkys5lsq6v/qgfx7UCsFo0Id3KDXMe1IpjsOOmlok2MXMd1IJhsP+mlok2MXCUaE1diV0wSkObEhWAiWBUm2hZnDGMRtXjghWewjoQZwrX4yNo3Yl0MCBNtYuQY8y6oyXvgGaQFQcGLOBRPWf9LbIge4RM5xjCWGmrxwIs+3qXqFXblGKE+weaaT3phYiw11CK88MSbObxaE3a3owQ8Whan4i2D9pLwCS97Kszh1ZS4EwxkPSeEqz1BvghyrvCwvYE3c5RqSFwKCh6F/QoQd06cDcljHc7YFJ+CXP5JUIsHcTzxDlK/uBcUzhDIdCaI2f7Ia1uQY4yJWmJ44RmlZ0HxYNJL9SqIcdeuiJFjjIlaYnhFK/YC7Iyo5ALaLQFr7mpHkMsvwbQgFrUEIZuQDcdFcNfA5EWbcFxEbcLGf4ahLyLu8kSw3kB7UfgU/CJq/FWMyg4j1r3dYbQl7G6jDyNT0XHMEUv7VviOY3KM+dNxjHwfJOfCDH0fJIyZFejXHyRlquWTrExsLiZr7KPUXrlFkKtFjf4x6apCtVo/mQri6IC8s1UAAAAASUVORK5CYII=
  8. // @include /^https?\:\/\/[a-zA-Z0-9]*.google.[^\/]+/
  9. // @include http://www.baidu.com/*
  10. // @include https://www.baidu.com/*
  11. // @license MPL-2.0
  12. // @copyright 2015+, f9y4ng
  13. // @grant none
  14.  
  15. // ==/UserScript==
  16.  
  17. if ("undefined" == typeof (jQuery)) {
  18. loadJs("for_google", "https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js", callbackFunction);
  19. }
  20. else {
  21. $(document).ready(function () {
  22. function baiduswitchgoogle() {
  23. $('.s_btn_wr').after('<div class="s_btn_wr bg" style="display:inline-block;margin-left:10px">\
  24. <input type="button" id="ggyx" value="Google一下" class="bg s_btn" ></div>');
  25. $('#ggyx').on({
  26. click: function () {
  27. var BSurl = GetUrlParam("tn"); //百度几个频道的命名和参数可以人道毁灭了,图片搜索没心情兼容。
  28. switch (BSurl) {
  29. case "news":
  30. BSurl = "tbm=nws&q=";
  31. break;
  32. case "vsearch":
  33. BSurl = "tbm=vid&q=";
  34. break;
  35. default:
  36. BSurl = "q=";
  37. }
  38. window.open("https://www.google.com/search?newwindow=1&hl=zh-CN&source=hp&" + BSurl + encodeURIComponent($('#kw').val()));
  39. return false;
  40. }
  41. });
  42. }
  43. if (GetUrlParam("wd").length > 0 || window.location.href.lastIndexOf("/s?") > 0) {
  44. baiduswitchgoogle();
  45. }
  46. //2018/11/07 F9y4ng 检测从baidu首页进入的搜索
  47. if (/^http(s)?:\/\/(www\.)?baidu\.com\/$/ig.test(window.location.href)) {
  48. $("#kw").on("blur", function () {
  49. if ($('#kw').val().length > 0) {
  50. setTimeout(function () {
  51. if ($('#ggyx').length < 1 && GetUrlParam("wd").length > 0) {
  52. baiduswitchgoogle();
  53. }
  54. }, 600);
  55. }
  56. });
  57. }
  58. });
  59. }
  60.  
  61. function callbackFunction() {
  62. $(document).ready(function () {
  63. function googleswitchbaidu() {
  64. $('#tsf').prepend('<div id="sfdiv_bd" style="display:inline-block;position:relative;height:0px;width:110px;right:-115px;\
  65. top:0px;float:right;"><button id="bdyx" class="lsbb kpbb" style="width:120px;height:49px;margin-top:-2px;cursor:pointer;\
  66. display: flex;border-radius: 8px;border: 1px solid #dfe1e5;box-shadow: none;border-radius: 24px;" type="button"><span \
  67. class="sbico" id="bdyxss" style="color:#fff;">\
  68. <svg style="fill: #fff;" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"\
  69. width="18px" height="18px" viewBox="0 0 64 64" xml:space="preserve">\
  70. <path d="M62.243,53.758L44.658,36.173C46.768,32.602,48,28.449,48,24C48,10.745,37.255,0,24,0S0,10.745,0,24s10.745,24,24,24\
  71. c4.449,0,8.602-1.232,12.173-3.342l17.584,17.584C54.843,63.329,56.343,64,58,64c3.314,0,6-2.686,6-6\
  72. C64,56.343,63.328,54.843,62.243,53.758z M24,42c-9.941,0-18-8.059-18-18c0-9.941,8.059-18,18-18c9.941,0,18,8.059,18,18\
  73. C42,33.941,33.941,42,24,42z"/></svg></span>\
  74. <span id="bdyxwz" style="font-size: 16px; margin-left:26px">百度一下</span></button></div>');
  75. $('#sfdiv_bd').off("click").on({
  76. click: function () {
  77. var kw = $('input[name="q"]').val();
  78. //获取属性标签容错
  79. if ("undefined" == typeof (kw)) {
  80. kw = GetUrlParam("q");
  81. }
  82. var GSurl = GetUrlParam("tbm");
  83. switch (GSurl) {
  84. case "isch":
  85. GSurl = "https://image.baidu.com/search/index?tn=baiduimage&ie=utf-8&word=";
  86. break;
  87. case "vid":
  88. GSurl = "https://www.baidu.com/sf/vsearch?pd=video&tn=vsearch&ie=utf-8&wd=";
  89. break;
  90. case "nws":
  91. GSurl = "https://www.baidu.com/s?tn=news&rtt=4&bsst=1&cl=2&wd=";
  92. break;
  93. default:
  94. GSurl = "https://www.baidu.com/s?ie=utf-8&rqlang=cn&wd=";
  95. }
  96. window.open(GSurl + encodeURIComponent(kw));
  97. return false;
  98. }
  99. });
  100. }
  101. if (window.location.hash.lastIndexOf("q=") > 0 || window.location.search.lastIndexOf("q=") > 0) {
  102. googleswitchbaidu();
  103. }
  104. //2019/05/21 F9y4ng 修正GOOGLE首页自动提交搜索优先级
  105. if (/^http(s)?:\/\/(www\.)?google\.\w+(\.\w+)?\/$/ig.test(window.location.href) || GetUrlParam("q") === null || GetUrlParam("q") === "") {
  106. var gfm = $('input[name="q"]');
  107. if ("undefined" == typeof (gfm)) {
  108. gfm = $("input[role='combobox']");
  109. }
  110. gfm.off('click').on({
  111. blur: function () {
  112. if (gfm.val().length > 0) {
  113. setTimeout(function () {
  114. $("form").submit();
  115. }, 200);
  116. }
  117. }
  118. });
  119. }
  120. var ua = myBrowser();
  121. if (GetUrlParam("tbm") !== "" && GetUrlParam("tbm") !== null) {
  122. $('#bdyxwz').css('margin-left', '2px');
  123. }
  124. if (ua == "FF" || ua == "Edge") {
  125. $('#bdyxwz').css('margin-top', '10px');
  126. $('#bdyxss').css('margin', '15px 2px 0 4px');
  127. }
  128. else {
  129. $('#bdyxwz').css('margin-top', '0px');
  130. $('#bdyxss').css('margin', '4px 2px 0 4px');
  131. }
  132. var elm = $('#bdyx');
  133. var startPos = $(elm).offset().top;
  134. $.event.add(window, "scroll", function () {
  135. var p = $(window).scrollTop();
  136. $(elm).css('height', ((p) > startPos - 5) ? '37px' : '49px');
  137. if (ua == "FF" || ua == "Edge") {
  138. $('#bdyxwz').css('margin-top', ((p) > startPos) ? '5px' : '10px');
  139. $('#bdyxss').css('margin', ((p) > startPos) ? '10px 2px 0 4px' : '15px 2px 0 4px');
  140. }
  141. if (GetUrlParam("tbm") !== "" && GetUrlParam("tbm") !== null) {
  142. $('#bdyx').css('margin-top', ((p) > startPos) ? '8px' : '-2px');
  143. }
  144. });
  145. });
  146. }
  147.  
  148. function loadJs(sid, jsurl, callback) {
  149. var nodeHead = document.getElementsByTagName('head')[0];
  150. var nodeScript = null;
  151. if (document.getElementById(sid) === null) {
  152. nodeScript = document.createElement('script');
  153. nodeScript.setAttribute('type', 'text/javascript');
  154. nodeScript.setAttribute('src', jsurl);
  155. nodeScript.setAttribute('id', sid);
  156. if (callback !== null) {
  157. nodeScript.onload = nodeScript.onreadystatechange = function () {
  158. if (nodeScript.ready) {
  159. return false;
  160. }
  161. if (!nodeScript.readyState || nodeScript.readyState == "loaded" || nodeScript.readyState == 'complete') {
  162. nodeScript.ready = true;
  163. callback();
  164. }
  165. };
  166. }
  167. nodeHead.appendChild(nodeScript);
  168. }
  169. else {
  170. if (callback !== null) {
  171. callback();
  172. }
  173. }
  174. }
  175.  
  176. function GetUrlParam(paraName) {
  177. var url = document.location.toString();
  178. var arrObj = url.split("?");
  179. if (arrObj.length > 1) {
  180. var arrPara = arrObj[1].split("&");
  181. var arr;
  182. for (var i = 0; i < arrPara.length; i++) {
  183. arr = arrPara[i].split("=");
  184. if (arr !== null && arr[0] == paraName) {
  185. return arr[1];
  186. }
  187. }
  188. return "";
  189. }
  190. else {
  191. return "";
  192. }
  193. }
  194.  
  195. function myBrowser() {
  196. var userAgent = navigator.userAgent;
  197. if (userAgent.indexOf("Firefox") > -1) {
  198. return "FF";
  199. }
  200. if (userAgent.indexOf("Edge") > -1) {
  201. return "Edge";
  202. }
  203. }