按下 / 键回到搜索框

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

目前為 2021-07-15 提交的版本,檢視 最新版本

// ==UserScript==
// @name         按下 / 键回到搜索框
// @namespace    http://tampermonkey.net/
// @version      0.01.1
// @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/*
// @grant        GM_addStyle
// ==/UserScript==
// weibo,zhihu,twitter,
// notios(ctrl+p)
console.log(0);
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 },
];

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

QingJ © 2025

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