// ==UserScript== // @name 按下 / 键回到搜索框 // @namespace http://tampermonkey.net/ // @version 0.01.3 // @description 在进行网站搜索时,浏览搜索结果时又想回到搜索框输入新的搜索关键词,又不想动鼠标,难受!安装该脚本后,即可通过按下 ` / ` 键回到搜索框,进行输入。 // @author missiont522 // @license MIT // @match https://*.baidu.com/* // @match https://*.bing.com/* // @match https://*.sogou.com/* // @match https://*.taobao.com/* // @include https://*.bilibili.com/* // @match https://*.greasyfork.org/* // @match https://*.douban.com/* // @match https://wht.im/* // @match https://fanyi.sogou.com/* // @match https://share.dmhy.com/* // @match https://weibo.com/* // @match https://www.shanbay.com/* // @include /^https:\/\/(kns\.)?(w*\.)?cnki\.net.*$/ // @include /^https:\/\/(\w*\.)?javdb(\d)*\.com.*$/ // @grant GM_addStyle // @downloadURL none // ==/UserScript== let siteList = [ { id: 0, name: 'baidu', query: '#kw.s_ipt', methods: defaultMeth }, { id: 1, name: 'google', query: '没有', methods: defaultMeth }, { id: 2, name: 'bing', query: '#sb_form_q.b_searchbox', methods: defaultMeth }, { id: 3, name: 'sogou', query: '#upquery.query', methods: defaultMeth }, { id: 4, name: 'taobao', query: '#q.search-combobox-input', methods: defaultMeth }, { id: 5, name: 'bilibili', query: '.nav-search-keyword', methods: defaultMeth }, { id: 6, name: 'search.bilibili', query: '#search-keyword', methods: defaultMeth }, { id: 7, name: 'greasyfork', query: '[type="search"]', methods: defaultMeth }, { id: 8, name: 'douban', query: '#inp-query', methods: doubanMeth }, { id: 9, name: 'wht.im', query: 'input.float-left.search-keyword', methods: defaultMeth }, { id: 10, name: 'fanyi.sogou', query: '#trans-input', methods: defaultMeth }, { id: 11, name: 'dmhy', query: 'input#keyword', methods: defaultMeth }, { id: 12, name: 'weibo', query: 'input.woo-input-main', methods: weiboMeth }, { id: 13, name: 'shanbay', query: '#search .input', methods: defaultMeth }, { id: 14, name: 'cnki', query: '.search-input', methods: defaultMeth }, ]; siteList.forEach((item) => { if (location.host.includes(item.name)) { const searchForm = document.querySelector(item.query); // console.dir(searchForm); document.documentElement.addEventListener('keydown', (e) => { if (e.target === document.body && e.key == '/') { searchForm.focus(); e.preventDefault(); let tempv = searchForm.value; searchForm.value = ''; searchForm.value = tempv; } }); item.methods(); } else { return false; } }); // function selector(query) { // query.map((element) => { // if (document.querySelector(element) == undefined) { // return false; // } else { // return document.querySelector(element); // } // // console.log(element); // }); // } function defaultMeth() { console.log(`${this.id},${this.name},'${this.query}'---`); } // function biliMeth() { // if (location.host.includes(item.name)) { // } // setTimeout(() => {}, 800); // } function doubanMeth() { document.querySelector('.mod-search').style.display = 'none'; GM_addStyle('.nav-primary {height: 8em;}'); GM_addStyle('.nav-search {bottom: -8px;left: 0;}'); GM_addStyle('.nav-search {bottom: -8px;left: 0;}'); GM_addStyle('.nav-search div.inp {width: 50em !important;height: 2.5em !important;line-height: 2.5em !important;}'); GM_addStyle('#inp-query {width:100%!important;'); GM_addStyle('.nav-search .inp-btn {right: 355px !important; height: 32.5px !important;}'); GM_addStyle('.nav-search .inp-btn input {height: 100% !important;}'); } function weiboMeth() { // document.querySelector('div.woo-box-flex.woo-box-alignCenter.woo-box-justifyCenter.SearchIcon_wrap_3fgul.Nav_icon_3GkaD').click(); }