Jisho.org forward slash to focus search bar

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

  1. // ==UserScript==
  2. // @name Jisho.org forward slash to focus search bar
  3. // @namespace https://github.com/sahlaysta/
  4. // @version 0.2
  5. // @description Focuses the search bar when forward slash is pressed, like on most sites
  6. // @author sahlaysta
  7. // @match https://jisho.org/*
  8. // @icon https://avatars.githubusercontent.com/u/12574115?s=200&v=4
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15. const searchBar = document.querySelector('#keyword');
  16. document.addEventListener('keydown', event => {
  17. if (!event.altKey && !event.ctrlKey && !event.isComposing && document.activeElement !== searchBar && event.key === '/') {
  18. searchBar.focus();
  19. searchBar.setSelectionRange(searchBar.value.length, searchBar.value.length);
  20. event.preventDefault();
  21. }
  22. });
  23. })();