// ==UserScript== // @name Google & baidu Switcher (ALL in One) // @namespace https://openuserjs.org/scripts/t3xtf0rm4tgmail.com/Google_baidu_Switcher_(ALL_in_One) // @author F9y4ng // @version 1.4.0.9 // @description 分别在百度和google的搜索结果页面增加搜索跳转按钮,使用到外链微软CDN的jquery-1.7.2.min.js,不懂跳墙使用GOOGLE的同学请自动忽略。自动判断百度和google对JQUERY的载入,并动态载入Jquery.js。 // @include /^https?\:\/\/[a-zA-Z0-9]*.google.[^\/]+/ // @include http://www.baidu.com/* // @include https://www.baidu.com/* // @license MPL // @copyright 2015+, f9y4ng // @grant none // @downloadURL none // ==/UserScript== if ("undefined" == typeof(jQuery)){ loadJs("for_google","https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js",callbackFunction); } else{ $(document).ready(function() { function baiduswitchgoogle() { $('.s_btn_wr').after('
'); $('#ggyx').on({ click: function () { window.open("https://www.google.com/search?source=hp&q=" + encodeURIComponent($('#kw') .val())); return false; } }); } if(window.location.search.lastIndexOf("wd=")>0 || window.location.href.lastIndexOf("/s?")>0){ baiduswitchgoogle(); } //检测从baidu首页进入的搜索(补漏) if(/^http(s)?:\/\/(www\.)?baidu\.com\/$/ig.test(window.location.href)){ $("#kw").off('click').on({ keydown: function () { if($('#ggyx').length<1 && $('#kw').val().length>0){baiduswitchgoogle();} } }).on({ paste: function () { if($('#ggyx').length<1){baiduswitchgoogle();} } }); } }); } function callbackFunction() { $(document).ready(function() { function googleswitchbaidu() { $('#tsf').prepend(''); $('#sfdiv_bd').off('click') .on({ click: function () { window.open("https://www.baidu.com/s?wd=" + encodeURIComponent($('#lst-ib') .val())); return false; } }); } if(window.location.hash.lastIndexOf("q=")>0 || window.location.search.lastIndexOf("q=")>0){ googleswitchbaidu(); } //2017/12/22 F9y4ng GOOGLE首页自动提交搜索,延时 if(/^http(s)?:\/\/(www\.)?google\.\w+(\.\w+)?\/$/ig.test(window.location.href)){ $("#lst-ib").off('click').on({ blur: function () { $("form").submit(); if($('#bdyx').length<1){ setTimeout(function(){googleswitchbaidu();},3000); } } }); } }); } function loadJs(sid,jsurl,callback){ var nodeHead = document.getElementsByTagName('head')[0]; var nodeScript = null; if(document.getElementById(sid) === null){ nodeScript = document.createElement('script'); nodeScript.setAttribute('type', 'text/javascript'); nodeScript.setAttribute('src', jsurl); nodeScript.setAttribute('id',sid); if (callback !== null) { nodeScript.onload = nodeScript.onreadystatechange = function(){ if (nodeScript.ready) { return false; } if (!nodeScript.readyState || nodeScript.readyState == "loaded" || nodeScript.readyState == 'complete') { nodeScript.ready = true; callback(); } }; } nodeHead.appendChild(nodeScript); } else { if(callback !== null){ callback(); } } }