Google & baidu Switcher (ALL in One)

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

当前为 2019-06-08 提交的版本,查看 最新版本

  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.1
  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. // @compatible Chrome + tampermonkey
  9. // @compatible Firefox + tampermonkey
  10. // @compatible Microsoft Edge + tampermonkey
  11. // @compatible opera + tampermonkey
  12. // @compatible safari //暂未测试
  13. // @include /^https?\:\/\/[a-zA-Z0-9]*.google.[^\/]+/
  14. // @include http://www.baidu.com/*
  15. // @include https://www.baidu.com/*
  16. // @license MPL-2.0
  17. // @copyright 2015+, f9y4ng
  18. // @grant none
  19.  
  20. // ==/UserScript==
  21.  
  22. if ("undefined" == typeof (jQuery)) {
  23. loadJs("for_google", "https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js", callbackFunction);
  24. }
  25. else {
  26. $(document).ready(function () {
  27. function baiduswitchgoogle() {
  28. $('.s_btn_wr').after('<div class="s_btn_wr bg" style="display:inline-block;margin-left:10px">\
  29. <input type="button" id="ggyx" value="Google一下" class="bg s_btn" ></div>');
  30. $('#ggyx').on({
  31. click: function () {
  32. var BSurl = GetUrlParam("tn"); //百度几个频道的命名和参数可以人道毁灭了,图片搜索没心情兼容。
  33. switch (BSurl) {
  34. case "news":
  35. BSurl = "tbm=nws&q=";
  36. break;
  37. case "vsearch":
  38. BSurl = "tbm=vid&q=";
  39. break;
  40. default:
  41. BSurl = "q=";
  42. }
  43. window.open("https://www.google.com/search?newwindow=1&hl=zh-CN&source=hp&" + BSurl + encodeURIComponent($('#kw').val()));
  44. return false;
  45. }
  46. });
  47. }
  48. if (GetUrlParam("wd").length > 0 || window.location.href.lastIndexOf("/s?") > 0) {
  49. baiduswitchgoogle();
  50. }
  51. //2018/11/07 F9y4ng 检测从baidu首页进入的搜索
  52. if (/^http(s)?:\/\/(www\.)?baidu\.com\/$/ig.test(window.location.href)) {
  53. $("#kw").on("blur", function () {
  54. if ($('#kw').val().length > 0) {
  55. setTimeout(function () {
  56. if ($('#ggyx').length < 1 && GetUrlParam("wd").length > 0) {
  57. baiduswitchgoogle();
  58. }
  59. }, 600);
  60. }
  61. });
  62. }
  63. });
  64. }
  65.  
  66. function callbackFunction() {
  67. $(document).ready(function () {
  68. function googleswitchbaidu() {
  69. $('#tsf').prepend('<div id="sfdiv_bd" style="display:inline-block;position:relative;height:0px;width:110px;right:-115px;\
  70. top:0px;float:right;"><button id="bdyx" class="lsbb kpbb" style="width:120px;height:49px;margin-top:-2px;cursor:pointer;\
  71. display: flex;border-radius: 8px;border: 1px solid #dfe1e5;box-shadow: none;border-radius: 24px;" type="button"><span \
  72. class="sbico" id="bdyxss" style="color:#fff;">\
  73. <svg style="fill: #fff;" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"\
  74. width="18px" height="18px" viewBox="0 0 64 64" xml:space="preserve">\
  75. <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\
  76. 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\
  77. 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\
  78. C42,33.941,33.941,42,24,42z"/></svg></span>\
  79. <span id="bdyxwz" style="font-size: 16px; margin-left:26px">百度一下</span></button></div>');
  80. $('#sfdiv_bd').off("click").on({
  81. click: function () {
  82. var kw = $('input[name="q"]').val();
  83. //获取属性标签容错
  84. if ("undefined" == typeof (kw)) {
  85. kw = GetUrlParam("q");
  86. }
  87. var GSurl = GetUrlParam("tbm");
  88. switch (GSurl) {
  89. case "isch":
  90. GSurl = "https://image.baidu.com/search/index?tn=baiduimage&ie=utf-8&word=";
  91. break;
  92. case "vid":
  93. GSurl = "https://www.baidu.com/sf/vsearch?pd=video&tn=vsearch&ie=utf-8&wd=";
  94. break;
  95. case "nws":
  96. GSurl = "https://www.baidu.com/s?tn=news&rtt=4&bsst=1&cl=2&wd=";
  97. break;
  98. default:
  99. GSurl = "https://www.baidu.com/s?ie=utf-8&rqlang=cn&wd=";
  100. }
  101. window.open(GSurl + encodeURIComponent(kw));
  102. return false;
  103. }
  104. });
  105. }
  106. if (window.location.hash.lastIndexOf("q=") > 0 || window.location.search.lastIndexOf("q=") > 0) {
  107. googleswitchbaidu();
  108. }
  109. //2019/05/21 F9y4ng 修正GOOGLE首页自动提交搜索优先级
  110. if (/^http(s)?:\/\/(www\.)?google\.\w+(\.\w+)?\/$/ig.test(window.location.href) || GetUrlParam("q") === null || GetUrlParam("q") === "") {
  111. var gfm = $('input[name="q"]');
  112. if ("undefined" == typeof (gfm)) {
  113. gfm = $("input[role='combobox']");
  114. }
  115. gfm.off('click').on({
  116. blur: function () {
  117. if (gfm.val().length > 0) {
  118. setTimeout(function () {
  119. $("form").submit();
  120. }, 200);
  121. }
  122. }
  123. });
  124. }
  125. var ua = myBrowser();
  126. if (GetUrlParam("tbm") !== "" && GetUrlParam("tbm") !== null) {
  127. $('#bdyxwz').css('margin-left', '2px');
  128. }
  129. if (ua == "FF" || ua == "Edge") {
  130. $('#bdyxwz').css('margin-top', '10px');
  131. $('#bdyxss').css('margin', '15px 2px 0 4px');
  132. }
  133. else {
  134. $('#bdyxwz').css('margin-top', '0px');
  135. $('#bdyxss').css('margin', '4px 2px 0 4px');
  136. }
  137. var elm = $('#bdyx');
  138. var startPos = $(elm).offset().top;
  139. $.event.add(window, "scroll", function () {
  140. var p = $(window).scrollTop();
  141. $(elm).css('height', ((p) > startPos - 5) ? '37px' : '49px');
  142. if (ua == "FF" || ua == "Edge") {
  143. $('#bdyxwz').css('margin-top', ((p) > startPos) ? '5px' : '10px');
  144. $('#bdyxss').css('margin', ((p) > startPos) ? '10px 2px 0 4px' : '15px 2px 0 4px');
  145. }
  146. if (GetUrlParam("tbm") !== "" && GetUrlParam("tbm") !== null) {
  147. $('#bdyx').css('margin-top', ((p) > startPos) ? '8px' : '-2px');
  148. }
  149. });
  150. });
  151. }
  152.  
  153. function loadJs(sid, jsurl, callback) {
  154. var nodeHead = document.getElementsByTagName('head')[0];
  155. var nodeScript = null;
  156. if (document.getElementById(sid) === null) {
  157. nodeScript = document.createElement('script');
  158. nodeScript.setAttribute('type', 'text/javascript');
  159. nodeScript.setAttribute('src', jsurl);
  160. nodeScript.setAttribute('id', sid);
  161. if (callback !== null) {
  162. nodeScript.onload = nodeScript.onreadystatechange = function () {
  163. if (nodeScript.ready) {
  164. return false;
  165. }
  166. if (!nodeScript.readyState || nodeScript.readyState == "loaded" || nodeScript.readyState == 'complete') {
  167. nodeScript.ready = true;
  168. callback();
  169. }
  170. };
  171. }
  172. nodeHead.appendChild(nodeScript);
  173. }
  174. else {
  175. if (callback !== null) {
  176. callback();
  177. }
  178. }
  179. }
  180.  
  181. function GetUrlParam(paraName) {
  182. var url = document.location.toString();
  183. var arrObj = url.split("?");
  184. if (arrObj.length > 1) {
  185. var arrPara = arrObj[1].split("&");
  186. var arr;
  187. for (var i = 0; i < arrPara.length; i++) {
  188. arr = arrPara[i].split("=");
  189. if (arr !== null && arr[0] == paraName) {
  190. return arr[1];
  191. }
  192. }
  193. return "";
  194. }
  195. else {
  196. return "";
  197. }
  198. }
  199.  
  200. function myBrowser() {
  201. var userAgent = navigator.userAgent;
  202. if (userAgent.indexOf("Firefox") > -1) {
  203. return "FF";
  204. }
  205. if (userAgent.indexOf("Edge") > -1) {
  206. return "Edge";
  207. }
  208. }