// ==UserScript==
// @name 搜索辅助小工具 - 淘宝,京东,百度,必应,谷歌,翻译,知乎,简书,维基百科等
// @namespace http://tampermonkey.net/
// @version 2.0
// @description 在网页右上角增加快捷搜索功能,功能如下:1.如果选择了文本,那么搜索文本,2.如果在百度,bing,谷歌,淘宝,京东,翻译等搜索框下,则搜索搜索框关键字。3.默认当前页面替换,单弹页面请按ctrl/shift/cmd键组合
// @require https://unpkg.com/vue/dist/vue.js
// @require https://cdn.staticfile.org/jquery/3.3.1/jquery.min.js
// @author Zszen
// @include https://*
// @include http://*
// @grant none
// @downloadURL none
// ==/UserScript==
//let config_isHidden = localStorage.getItem("config_isHidden")==null? false:localStorage.getItem("config_isHidden");
(function () {
'use strict'
setTimeout(function () {
//console.log('config_isHidden',config_isHidden)
let div = $('
')
$('body').append(div)
let title = $('{{valueForTitle}}
')
div.append(title)
let items = $('')//{{item.title}}
div.append(items)
let intro = $('')
div.append(intro)
// @ts-ignore
let divApp = new Vue({
el: '#zszen',
data: {
title: '小工具z',
valueForTitle: '小工具z',
hidden: true,
widthVal:0,
heightVal:0,
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/'},
]
},
computed:{
isHidden:{
set:function(val){
//console.log(val)
this.hidden = val;
//config_isHidden = this.hidden;
//localStorage.setItem("config_isHidden", config_isHidden);
if(this.hidden){
this.valueForTitle= 'TOOLz';
this.heightVal = "25px";
this.widthVal = '53px';
}else{
this.valueForTitle= this.title;
this.heightVal = "270px";
//console.log('123',$('label.bottom.tip').offset())
//this.heightVal = $('label.bottom.tip').offset().top+$('.bottom.tip').height()
this.widthVal = '115px';
}
},
get:function(val){
return this.hidden;
}
}
},
methods: {
mouseover:function(){
this.isHidden = false;
},
mouseout:function(){
this.isHidden = true;
},
onClick: function (evt, val) {
//window.location.href = this.infos[val].link
var str = window.location.href;
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(this.infos[val].link+keyword,"_blank");
}else{
window.open(this.infos[val].link+keyword,"_self");
}
},
/*onClickTitle:function(){
//console.log('click', !this.isHidden)
this.isHidden = !this.isHidden;
}*/
}
});
//divApp.isHidden = !(config_isHidden==null || config_isHidden==false);
divApp.isHidden = true;
}, 1000)
function getSelectedText() {
if (window.getSelection) {
return window.getSelection().toString();
} else if (document.selection) {
return document.selection.createRange().text;
}
return ''
}
// Your code here...
})()