Jisho.org forward slash to focus search bar

Focuses the search bar when forward slash is pressed, like on most sites

目前为 2022-06-27 提交的版本。查看 最新版本

// ==UserScript==
// @name         Jisho.org forward slash to focus search bar
// @namespace    https://github.com/sahlaysta/
// @version      0.1
// @description  Focuses the search bar when forward slash is pressed, like on most sites
// @author       sahlaysta
// @match        https://jisho.org/*
// @icon         https://avatars.githubusercontent.com/u/12574115?s=200&v=4
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';
    const searchBar = document.querySelector('#keyword');
    const forwardSlashKeyCode = 191;
    document.addEventListener('keydown', event => {
       if (!event.altKey && !event.ctrlKey && !event.isComposing && document.activeElement !== searchBar && event.keyCode === forwardSlashKeyCode) {
           const selectionIndex = searchBar.value.length;
           searchBar.focus();
           searchBar.setSelectionRange(selectionIndex, selectionIndex);
           event.preventDefault();
       }
    });
})();

QingJ © 2025

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