Greasy Fork is available in English.
建立搜索引擎允许的语法上使我们更快找到自己所需要的内容!
当前为
// ==UserScript==
// @name GoogleEasySearch
// @version 1.8
// @license MIT
// @description 建立搜索引擎允许的语法上使我们更快找到自己所需要的内容!
// @author 小乘字节
// @match *.google.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=google.com
// @grant none
// @require http://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.0/jquery.min.js
// @namespace http://t.csdn.cn/D9iH7
// ==/UserScript==
(function() {
'use strict';
// 配置Google搜索语法
let dict = [
{
"value": "AND ",
"describe": "并且"
},
{
"value": "OR ",
"describe": "或者"
},
{
"value": "intitle:",
"describe": "标题包含"
}, {
"value": "intext:",
"describe": "内容包含"
}, {
"value": "site:",
"describe": "指定网站"
}, {
"value": "index of /",
"describe": "网站目录"
}, {
"value": "inurl:",
"describe": "指定路径"
}, {
"value": "filetype:",
"describe": "文件类型"
}, {
"value": "related:",
"describe": "相似网站"
}, {
"value": "link:",
"describe": "查找外链"
}
];
// 统一管理CSS样式 type: 1(下拉列表的父级元素)、2(下拉列表、dict)、3(form表单样式)
function earySearchCSS(type, el) {
switch (type) {
case 1:
el.css({
"position": "absolute",
"top": "38px",
"left": earySearchX
});
break;
case 2:
el.css({
"width": "100px",
"text-align": "center"
});
break;
case 3:
el.css({
"position": "relative"
});
break;
}
}
let form = $("form[action='/search']");
let q = form.find("input[name='q']");
let RNNXgb=form.find("div.RNNXgb");
let earySearchX = RNNXgb.offset().left+RNNXgb.width()+10;
let newValue = q.val();
let logo = form.find("div.logo");
let sfbg = $("div.sfbg");
// 添加相关元素
RNNXgb.before(`<div class="easySearchText" style="margin:0 0 5px 0;color:#758a99;">
模糊匹配多个【*】、模糊匹配单个【?】、精确匹配【" "】、过滤【-】、包含【+】
</div>`);
sfbg.height(sfbg.height()+20);
logo.css("top", form.find(".easySearchText").height()+"px");
form.append(`<div class='earySearch'>
<select class='earySearchDict' style="color:#758a99;">
<option value='-1'>--进阶搜索--</option>
<option value='http://t.csdn.cn/i6fPD' style="color:#00e09e;">使用帮助</option>
</select>
</div>`);
let earySearch = form.find("div.earySearch");
let earySearchDict = earySearch.find(".earySearchDict");
dict.map((data)=>{
earySearchDict.append(`<option style="font-weight: 700;" value='${data.value}'>${data.describe}</option>`);
});
earySearchCSS(3, form);
earySearchCSS(1, earySearch);
earySearchCSS(2, earySearchDict);
// 监听select元素
earySearchDict.change(function() {
let index = this.selectedIndex;
if (index === 0) {
return;
}else if(index === 1){
window.location.href = this.value;
return;
}
// 向搜索框添加内容
q.val(newValue.concat(" ", this.value));
// 1秒后重置选项
setTimeout(()=>{
this.value = "-1"
}, 1000);
});
// 获取键盘输入的内容
q.on("input", function() {
clearTimeout(this.myTimeOut)
let _this = this;
this.myTimeOut = setTimeout(()=>{
newValue = _this.value;
}, 300)
});
// 清空搜索框
let ariaLavels = [$("div[aria-label='清除']"), $("div[aria-label=' Clear']")];
ariaLavels.map((ariaLavel)=>{
console.log(ariaLavel);
ariaLavel.on('click', function() {
newValue = '';
})
});
})();