按下 / 键回到搜索框

在进行网站搜索时,浏览搜索结果时又想回到搜索框输入新的搜索关键词,又不想动鼠标,难受!安装该脚本后,即可通过按下 ` / ` 键回到搜索框,进行输入。

目前为 2021-10-08 提交的版本。查看 最新版本

// ==UserScript==
// @name         按下 / 键回到搜索框
// @namespace    http://tampermonkey.net/
// @version      0.01.2
// @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://*.gf.qytechs.cn/*
// @match        https://*.douban.com/*
// @match        https://wht.im/*
// @match        https://fanyi.sogou.com/*
// @match        https://share.dmhy.com/*
// @match        https://weibo.com/*
// @grant        GM_addStyle
// ==/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 },
];

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 defaultMeth() {
  console.log(`${this.id},${this.name},'${this.query}'---`);
}


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() {
}

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址