Google & baidu Switcher (ALL in One)

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

当前为 2020-07-11 提交的版本,查看 最新版本

  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. // @homepageURL https://greasyfork.org/zh-CN/scripts/12909-google-baidu-switcher-all-in-one
  5. // @feedback-url https://greasyfork.org/zh-CN/scripts/12909-google-baidu-switcher-all-in-one/feedback
  6. // @author F9y4ng
  7. // @version 1.6.4.1
  8. // @description 分别在百度和google的搜索结果页面增加搜索跳转按钮,使用到jquery的jquery-1.7.2.min.js,不懂跳墙使用GOOGLE的同学请自动忽略。自动判断百度和google对JQUERY的载入,并动态载入Jquery.js。
  9. // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAHpSURBVFhH7Ze7SsRAFIYXLSwUaxXEQlEUfQIrWxUsfAk7G2+VYGHnO9j7AjYqaClYWCtWFlp5QfDS6P8lORCGTHZGswnC/vDBzDlz/kkys5lsq6v/qgfx7UCsFo0Id3KDXMe1IpjsOOmlok2MXMd1IJhsP+mlok2MXCUaE1diV0wSkObEhWAiWBUm2hZnDGMRtXjghWewjoQZwrX4yNo3Yl0MCBNtYuQY8y6oyXvgGaQFQcGLOBRPWf9LbIge4RM5xjCWGmrxwIs+3qXqFXblGKE+weaaT3phYiw11CK88MSbObxaE3a3owQ8Whan4i2D9pLwCS97Kszh1ZS4EwxkPSeEqz1BvghyrvCwvYE3c5RqSFwKCh6F/QoQd06cDcljHc7YFJ+CXP5JUIsHcTzxDlK/uBcUzhDIdCaI2f7Ia1uQY4yJWmJ44RmlZ0HxYNJL9SqIcdeuiJFjjIlaYnhFK/YC7Iyo5ALaLQFr7mpHkMsvwbQgFrUEIZuQDcdFcNfA5EWbcFxEbcLGf4ahLyLu8kSw3kB7UfgU/CJq/FWMyg4j1r3dYbQl7G6jDyNT0XHMEUv7VviOY3KM+dNxjHwfJOfCDH0fJIyZFejXHyRlquWTrExsLiZr7KPUXrlFkKtFjf4x6apCtVo/mQri6IC8s1UAAAAASUVORK5CYII=
  10. // @compatible Chrome + Tampermonkey
  11. // @compatible Firefox + Tampermonkey
  12. // @compatible Microsoft Edge + Tampermonkey
  13. // @compatible Opera + Tampermonkey
  14. // @compatible Safari + Tampermonkey • Safari
  15. // @include *://encrypted.google.*/search*
  16. // @include *://*.google*/search*
  17. // @include *://*.google*/webhp*
  18. // @include *://www.google*/ac-notexist*
  19. // @include http://www.baidu.com/*
  20. // @include https://www.baidu.com/*
  21. // @license MPL-2.0
  22. // @create 2015-10-07
  23. // @copyright 2015-2020, F9y4ng
  24. // @grant none
  25.  
  26. // ==/UserScript==
  27.  
  28. if ("undefined" == typeof (jQuery)) {
  29. loadJs("for_google", "https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js", callbackFunction);
  30. }
  31. else {
  32. $(document).ready(function () {
  33. function baiduswitchgoogle() {
  34. if (document.querySelector("#ggyx") == null) {
  35. $('.s_btn_wr').after('<div class="s_btn_wr bg" style="width:0px;display:inline-block;margin-left:10px"><input type="button" id="ggyx" value="Google一下" class="ggyx" ></div>');
  36. $('.ggyx').css({
  37. 'width': '112px',
  38. 'height': '44px',
  39. 'color': '#fff',
  40. 'letter-spacing': '1px',
  41. 'background': '#4e71f2',
  42. 'border': '0',
  43. 'cursor': 'pointer',
  44. 'border-radius': '10px',
  45. 'font-size': '14px'
  46. });
  47. $('form.fm .s_btn').css({
  48. 'background': '#4e71f2',
  49. 'border-bottom': '1px solid #2d78f4'
  50. });
  51. hoverhandle($('form.fm .s_btn'));
  52. hoverhandle($('#ggyx'));
  53. $('#u').css({
  54. 'z-index': '1'
  55. });
  56. $('#ggyx').off("click").on({
  57. click: function () {
  58. var BSurl = GetUrlParam("tn");
  59. switch (BSurl) {
  60. case "news":
  61. BSurl = "tbm=nws&q=";
  62. break;
  63. case "vsearch":
  64. BSurl = "tbm=vid&q=";
  65. break;
  66. default:
  67. BSurl = "q=";
  68. }
  69. window.open("https://www.google.com/search?newwindow=1&hl=zh-CN&source=hp&" + BSurl + encodeURIComponent($('#kw').val()));
  70. return false;
  71. }
  72. });
  73. }
  74. }
  75.  
  76. function hoverhandle(e) {
  77. e.hover(function () {
  78. e.css({
  79. 'background': '#4662D9',
  80. 'border': '1px solid #2d78f4'
  81. })
  82. }, function () {
  83. e.css({
  84. 'background': '#4e71f2',
  85. 'border': '1px solid #2d78f4'
  86. })
  87. });
  88. }
  89. //2019/12/07 F9y4ng 检测从baidu首页进入的搜索&自动提交
  90. if (/^http(s)?:\/\/(www\.)?baidu\.com\/$/ig.test(window.location.href)) {
  91. $("#kw").on("blur", function () {
  92. if ($('#kw').val().length > 0) {
  93. setTimeout(function () {
  94. if ($('#ggyx').length < 1 && !(GetUrlParam("wd").length > 0 || GetUrlParam("word").length > 0)) {
  95. $('form').submit();
  96. }
  97. }, 600);
  98. }
  99. });
  100. }
  101. else {
  102. if (GetUrlParam("wd").length > 0 || window.location.href.lastIndexOf("/s?") > 0 || GetUrlParam("word").length > 0 || window.location.href.lastIndexOf("/baidu?") > 0) {
  103. baiduswitchgoogle();
  104. }
  105. }
  106. var elm = $('#ggyx');
  107. var startPos = $(elm).offset().top;
  108. $.event.add(window, "scroll", function () {
  109. var p = $(window).scrollTop();
  110. $(elm).css('height', ((p) > startPos - 0) ? '40px' : '44px');
  111. });
  112. });
  113. }
  114.  
  115. function callbackFunction() {
  116. $(document).ready(function () {
  117. var browser = {
  118. versions: function () {
  119. var u = navigator.userAgent;
  120. return {
  121. Firefox: u.indexOf('Firefox') > -1,
  122. Edge: u.indexOf('Edge') > -1,
  123. Chrome: u.indexOf('Chrome') > -1 && u.indexOf('Edg') == -1,
  124. Microsoft_Edge: u.indexOf('Edg') > -1 && u.indexOf('Edge') == -1,
  125. Chromium: u.indexOf('Chrome') > -1
  126. };
  127. }()
  128. }
  129.  
  130. function googleswitchbaidu() {
  131. if (document.querySelector("#sfdiv_bd") == null) {
  132. $('button[type="submit"]').closest('div').first().after('<div id="sfdiv_bd" style="position:relative;float:right;height:0px"><button id="bdyx" style="cursor: pointer; display: flex; border: 1px solid transparent; background: #1a73e8; box-shadow: none; border-radius: 24px; width: 120px; height: 46px;" type="button"><span class="sbico" id="bdyxss" style="color:#fff;"><svg style="fill: #fff;" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="18px" height="18px" viewBox="0 0 64 64" xml:space="preserve"><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 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 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 C42,33.941,33.941,42,24,42z"/></svg></span><span id="bdyxwz" style="color: rgb(255, 255, 255); font-size: 16px; margin-left: 26px; font-weight: 700;">百度一下</span></button></div>');
  133. $('#sfdiv_bd').css({
  134. 'top': '-46px',
  135. 'right': '-130px'
  136. });
  137. $('#bdyx').css({
  138. 'width': '120px',
  139. 'height': '46px'
  140. });
  141. hoverhandlel($('#bdyx'));
  142. $('#sfdiv_bd').off("click").on({
  143. click: function () {
  144. var kw = $('input[name="q"]').val();
  145. //获取属性标签容错
  146. if ("undefined" == typeof (kw)) {
  147. kw = GetUrlParam("q");
  148. }
  149. var GSurl = GetUrlParam("tbm");
  150. switch (GSurl) {
  151. case "isch":
  152. GSurl = "https://image.baidu.com/search/index?tn=baiduimage&ie=utf-8&word=";
  153. break;
  154. case "vid":
  155. GSurl = "https://www.baidu.com/sf/vsearch?pd=video&tn=vsearch&ie=utf-8&wd=";
  156. break;
  157. case "nws":
  158. GSurl = "https://www.baidu.com/s?tn=news&rtt=4&bsst=1&cl=2&wd=";
  159. break;
  160. case "shop":
  161. GSurl = "https://b2b.baidu.com/s?fr=wwwt&q=";
  162. break;
  163. default:
  164. GSurl = "https://www.baidu.com/s?ie=utf-8&rqlang=cn&wd=";
  165. }
  166. window.open(GSurl + encodeURIComponent(kw));
  167. return false;
  168. }
  169. });
  170. }
  171. }
  172. if (window.location.hash.lastIndexOf("q=") > 0 || window.location.search.lastIndexOf("q=") > 0) {
  173. googleswitchbaidu();
  174. }
  175.  
  176. function hoverhandlel(e) {
  177. e.hover(function () {
  178. e.css({
  179. 'background': '#2b7de9',
  180. 'border': '1px solid transparent'
  181. })
  182. }, function () {
  183. e.css({
  184. 'background': '#1a73e8',
  185. 'border': '1px solid transparent'
  186. })
  187. });
  188. }
  189. //2019/05/21 F9y4ng 修正GOOGLE首页自动提交搜索优先级
  190. if (/^http(s)?:\/\/(www\.)?google\.\w+(\.\w+)?\/$/ig.test(window.location.href) || GetUrlParam("q") === null || GetUrlParam("q") === "") {
  191. var gfm = $('input[name="q"]');
  192. if ("undefined" == typeof (gfm)) {
  193. gfm = $("input[role='combobox']");
  194. }
  195. gfm.off('click').on({
  196. blur: function () {
  197. if (gfm.val().length > 0) {
  198. setTimeout(function () {
  199. $("form").submit();
  200. }, 200);
  201. }
  202. }
  203. });
  204. }
  205. if (GetUrlParam("tbm") !== "" && GetUrlParam("tbm") !== null) {
  206. $('#bdyxwz').css('margin-left', '2px');
  207. }
  208. if (GetUrlParam("tbm") == "fin") {
  209. $('#bdyxwz').css('margin', '-2px 0 0 24px');
  210. }
  211. $('#bdyxwz').css('margin-top', '10px');
  212. $('#bdyxss').css('margin', '13px 2px 0 4px');
  213.  
  214. var elm = $('#bdyx');
  215. var startPos = $(elm).offset().top;
  216. $.event.add(window, "scroll", function () {
  217. var p = $(window).scrollTop();
  218. $(elm).css('height', ((p) > startPos - 0) ? '34px' : '46px');
  219. $(elm).css('margin-top', ((p) > startPos - 0) ? '12px' : '0px');
  220. $('#bdyxwz').css('margin-top', ((p) > startPos) ? '4px' : '10px');
  221. $('#bdyxwz').css('font-weight', ((p) > startPos) ? '500' : '700');
  222. $('#bdyxss').css('margin', ((p) > startPos) ? '7px 2px 0 4px' : '13px 2px 0 4px');
  223. if (GetUrlParam("tbm") !== "" && GetUrlParam("tbm") !== null) {
  224. $('#bdyx').css('margin-top', ((p) > startPos) ? '1px' : '0px');
  225. }
  226. });
  227. });
  228. }
  229.  
  230. function loadJs(sid, jsurl, callback) {
  231. var nodeHead = document.getElementsByTagName('head')[0];
  232. var nodeScript = null;
  233. if (document.getElementById(sid) === null) {
  234. nodeScript = document.createElement('script');
  235. nodeScript.setAttribute('type', 'text/javascript');
  236. nodeScript.setAttribute('src', jsurl);
  237. nodeScript.setAttribute('id', sid);
  238. if (callback !== null) {
  239. nodeScript.onload = nodeScript.onreadystatechange = function () {
  240. if (nodeScript.ready) {
  241. return false;
  242. }
  243. if (!nodeScript.readyState || nodeScript.readyState == "loaded" || nodeScript.readyState == 'complete') {
  244. nodeScript.ready = true;
  245. callback();
  246. }
  247. };
  248. }
  249. nodeHead.appendChild(nodeScript);
  250. }
  251. else {
  252. if (callback !== null) {
  253. callback();
  254. }
  255. }
  256. }
  257.  
  258. function GetUrlParam(paraName) {
  259. var url = document.location.toString();
  260. var arrObj = url.split("?");
  261. if (arrObj.length > 1) {
  262. var arrPara = arrObj[1].split("&");
  263. var arr;
  264. for (var i = 0; i < arrPara.length; i++) {
  265. arr = arrPara[i].split("=");
  266. if (arr !== null && arr[0] == paraName) {
  267. return arr[1];
  268. }
  269. }
  270. return "";
  271. }
  272. else {
  273. return "";
  274. }
  275. }