// ==UserScript==
// @name 搜索辅助小工具 - 淘宝,京东,百度,必应,谷歌,翻译等
// @namespace http://tampermonkey.net/
// @version 3.1
// @description 在网页右上角增加快捷搜索功能,功能如下:1.如果选择了文本,那么搜索文本,2.如果在百度,bing,谷歌,淘宝,京东,翻译等搜索框下,则搜索搜索框关键字。3.默认当前页面替换,单弹页面请按ctrl/shift/cmd键组合。摒弃了vue,因为和很多网站都存在冲突
// @require https://cdn.staticfile.org/jquery/3.3.1/jquery.min.js
// @author Zszen
// @include https://*
// @include http://*
// @grant none
// @downloadURL none
// ==/UserScript==
//https://unpkg.com/vue/dist/vue.js
(function () {
'use strict'
let isDebug = 0
DLOG('===小工具z===');
setTimeout(function () {
DLOG('===init===');
let infos = [
{title: '百度搜索', link: "https://www.baidu.com/s?wd="},
{title: 'Bing搜索', link: 'https://www.bing.com/search?q='},
{title: 'Google搜索', link: 'https://www.google.com/search?q='},
{title: '百度翻译', link: 'https://fanyi.baidu.com/#en/zh/'},
{title: 'Google翻译', link: 'https://translate.google.cn/#view=home&op=translate&sl=en&tl=zh-CN&text='},
{title: '淘宝搜索', link: 'https://s.taobao.com/search?q='},
{title: '京东搜索', link: 'https://search.jd.com/Search?keyword='},
{title: '简书', link: 'https://www.jianshu.com/search?q='},
{title: '知乎', link: 'https://www.zhihu.com/search?type=content&q='},
{title: '维基百科', link: 'https://zh.wikipedia.org/wiki/'}
];
let div = $('
');
$('body').append(div);
let title = $('TOOLz
');
div.append(title);
let items = $('');//{{item.title}}
div.append(items);
for(let info of infos){
// let btn = $('');
let btn = $('
')
btn.on('click',(evt)=>{
dealLink(evt, evt.currentTarget.getAttribute('link'),window.location.href);
})
btn.on('mouseover',(evt)=>{
// evt.currentTarget
evt.currentTarget.style.color = '#ff0000';
})
btn.on('mouseout',(evt)=>{
// dealLink(evt, evt.currentTarget.getAttribute('link'),window.location.href);
evt.currentTarget.style.color = '#333333';
})
DLOG(info.title);
items.append(btn);
}
let intro = $('');
items.append(intro);
div.on('mouseover',showList)
div.on('mouseout',hideList)
//
hideList();
}, 1000)
function showList(){
$('h4#title').children().html('小工具z');
$('div#zszen').css({width:'115px',height:'215px'})
$('div#zszen').find('font#title').css({'font-size':16})
$('div#zszen').find('div#itemList').show();
}
function hideList(){
$('h4#title').children().html('TOOLz');
$('div#zszen').css({width:'53px',height:'25px'})
$('div#zszen').find('font#title').css({'font-size':13})
$('div#zszen').find('div#itemList').hide();
}
function dealLink(evt,link,currentLink){
if(isDebug){
DLOG(link);
return;
}
var str = currentLink;
var keyword = "";
if(str.indexOf("www.baidu.com")!=-1){
console.log("百度:");
keyword = $('input.s_ipt').val();
}else if(str.indexOf("fanyi.baidu.com")!=-1){
keyword = $('textarea.textarea').val();
}else if(str.indexOf("bing.com")!=-1){
keyword = $('input.b_searchbox').val();
}else if(str.indexOf("www.google.com")!=-1){
keyword = $('input[role]').val();
}else if(str.indexOf("translate.google.com")!=-1 || str.indexOf("translate.google.cn")!=-1){
keyword = $('textarea#source').value;
}else if(str.indexOf("taobao.com")!=-1){
keyword = $('input.search-combobox-input').val();
}else if(str.indexOf("jd.com")!=-1){
keyword = $('input.text#key').val();
}else if(str.indexOf("jianshu.com")!=-1){
keyword = $('input.search-input').val();
}else if(str.indexOf("zhihu.com")!=-1){
keyword = $('input.Input#Popover5-toggle').val();
}else if(str.indexOf("wikipedia.org")!=-1){
var str1 = window.location.href;
var arr1 = str1.split("/");
keyword = arr1[arr1.length-1];
}else{
console.log("其他");
}
if(getSelectedText()!=''){
keyword = getSelectedText();
}
//console.log(evt)
if(evt.shiftKey || evt.ctrlKey || evt.metaKey){
window.open(link+keyword,"_blank");
}else{
window.open(link+keyword,"_self");
}
}
function getSelectedText() {
if (window.getSelection) {
return window.getSelection().toString();
} else if (document.selection) {
return document.selection.createRange().text;
}
return ''
}
function DLOG(...args){
if(isDebug) console.log.call(this,args);
}
// Your code here...
})()