Google & baidu Switcher (ALL in One)

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

当前为 2018-11-25 提交的版本,查看 最新版本

  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.4.4.2
  6. // @description 分别在百度和google的搜索结果页面增加搜索跳转按钮,使用到外链微软CDN的jquery-1.7.2.min.js,不懂跳墙使用GOOGLE的同学请自动忽略。自动判断百度和google对JQUERY的载入,并动态载入Jquery.js。
  7. // @icon https://www.androidpolice.com/wp-content/uploads/2014/06/nexusae0_io2014_thumb2.png
  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. window.open("https://www.google.com/search?newwindow=1&hl=zh-CN&source=hp&q=" + encodeURIComponent($('#kw').val()));
  28. return false;
  29. }
  30. });
  31. }
  32. if (GetUrlParam("wd").length > 0 || window.location.href.lastIndexOf("/s?") > 0) {
  33. baiduswitchgoogle();
  34. }
  35. //2018/11/07 F9y4ng 检测从baidu首页进入的搜索(修正自动提交的Bug)
  36. if (/^http(s)?:\/\/(www\.)?baidu\.com\/$/ig.test(window.location.href)) {
  37. $("#kw").on("blur", function () {
  38. if ($('#kw').val().length > 0) {
  39. setTimeout(function () {
  40. if ($('#ggyx').length < 1 && GetUrlParam("wd").length > 0) {
  41. baiduswitchgoogle();
  42. }
  43. }, 600);
  44. }
  45. });
  46. }
  47. });
  48. }
  49.  
  50. function callbackFunction() {
  51. $(document).ready(function () {
  52. function googleswitchbaidu() {
  53. $('#tsf').prepend('<div id="sfdiv_bd" style="display:inline-block;position:relative;height:0px;width:110px;right:-115px;top:-4px;float:right;">\
  54. <button id="bdyx" class="lsbb kpbb" style="height:45px;margin-top:4px;cursor:pointer" type="button"><span class="sbico" style="color:#fff;margin-top:-4px">\
  55. <svg focusable="false" style="fill: #fff;" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M15.5 14h-.79l-.28-.27A6.471 6.471 0\
  56. 0 0 16 9.5 6.5 6.5 0 1 0 9.5 16c1.61 0 3.09-.59 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 \
  57. 9.5 11.99 14 9.5 14z"></path></svg></span><span style="font-size:16px;">百度一下</span></button></div>');
  58. $('#sfdiv_bd').off("click").on({
  59. click: function () {
  60. var kw = $('input[name="q"]').val();
  61. //获取属性标签容错
  62. if ("undefined" == typeof (kw)) {
  63. kw = GetUrlParam("q");
  64. }
  65. window.open("https://www.baidu.com/s?ie=utf-8&rqlang=cn&wd=" + encodeURIComponent(kw));
  66. return false;
  67. }
  68. });
  69. }
  70. if (window.location.hash.lastIndexOf("q=") > 0 || window.location.search.lastIndexOf("q=") > 0) {
  71. googleswitchbaidu();
  72. }
  73. //2018/11/07 F9y4ng GOOGLE首页自动提交搜索修正
  74. if (/^http(s)?:\/\/(www\.)?google\.\w+(\.\w+)?\/$/ig.test(window.location.href) || GetUrlParam("q") === null || GetUrlParam("q") === "") {
  75. var gfm = $('input[name="q"]');
  76. if ("undefined" == typeof (gfm)) {
  77. gfm = $("input[role='combobox']");
  78. }
  79. gfm.off('click').on({
  80. blur: function () {
  81. if (gfm.val().length > 0) {
  82. $("form").submit();
  83. }
  84. }
  85. });
  86. }
  87. });
  88. }
  89.  
  90. function loadJs(sid, jsurl, callback) {
  91. var nodeHead = document.getElementsByTagName('head')[0];
  92. var nodeScript = null;
  93. if (document.getElementById(sid) === null) {
  94. nodeScript = document.createElement('script');
  95. nodeScript.setAttribute('type', 'text/javascript');
  96. nodeScript.setAttribute('src', jsurl);
  97. nodeScript.setAttribute('id', sid);
  98. if (callback !== null) {
  99. nodeScript.onload = nodeScript.onreadystatechange = function () {
  100. if (nodeScript.ready) {
  101. return false;
  102. }
  103. if (!nodeScript.readyState || nodeScript.readyState == "loaded" || nodeScript.readyState == 'complete') {
  104. nodeScript.ready = true;
  105. callback();
  106. }
  107. };
  108. }
  109. nodeHead.appendChild(nodeScript);
  110. }
  111. else {
  112. if (callback !== null) {
  113. callback();
  114. }
  115. }
  116. }
  117.  
  118. function GetUrlParam(paraName) {
  119. var url = document.location.toString();
  120. var arrObj = url.split("?");
  121. if (arrObj.length > 1) {
  122. var arrPara = arrObj[1].split("&");
  123. var arr;
  124. for (var i = 0; i < arrPara.length; i++) {
  125. arr = arrPara[i].split("=");
  126. if (arr !== null && arr[0] == paraName) {
  127. return arr[1];
  128. }
  129. }
  130. return "";
  131. }
  132. else {
  133. return "";
  134. }
  135. }