// ==UserScript== // @name Google & baidu Switcher (修改版) // @namespace http://tampermonkey.net/ // @author ZeroCode // @version 0.2 // @description 基于Google_baidu_Switcher_(ALL_in_One)修改,分别在百度和google的搜索结果页面增加搜索跳转按钮。 // @include https://www.google.* // @include http://www.google.* // @include https://ipv6.google.* // @include http://ipv6.google.* // @include http://www.baidu.com/* // @include https://www.baidu.com/* // @include http://image.baidu.com/* // @include https://image.baidu.com/* // @require https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js // @downloadURL none // ==/UserScript== (function() { 'use strict'; if(location.host.indexOf("baidu.com") > -1){ baidu2google(); }else if(location.host.indexOf(".google.") > -1){ google2baidu(); } function baidu2google() { $('.s_btn_wr').after('
'); var s_url = "https://www.google.com/search?newwindow=1&hl=zh-CN&source=hp"; if(getUrlParam("tn") == "baiduimage") { s_url = s_url + "&tbm=isch"; } $('#google_search').on({ click: function () { window.open(s_url + "&q=" + encodeURIComponent($('#kw').val())); return false; } }); } function google2baidu(){ //alert(location.host); $('#tsf').prepend('
'); var s_url = "https://www.google.com/search?newwindow=1&hl=zh-CN&source=hp"; $('#sfdiv_bd').on( "click", function(){ var kw = $('input[name="q"]').val(); //获取属性标签容错 if ("undefined" == typeof (kw)) { kw = getUrlParam("q"); } var s_url = "https://www.baidu.com/s?ie=utf-8&rqlang=cn"; if(getUrlParam("tbm") == "isch") s_url = "https://image.baidu.com/search/index?tn=baiduimage&ie=utf-8&rqlang=cn"; window.open(s_url + "&wd=" + encodeURIComponent(kw)); return false; } ); } function getUrlParam(name) { //构造一个含有目标参数的正则表达式对象 var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //匹配目标参数 var r = window.location.search.substr(1).match(reg); //返回参数值 if (r != null) return unescape(r[2]); return null; } })();