Fextralife Searchbox Focus

Target the searchbox on Fextralife wikis with a hotkey

질문, 리뷰하거나, 이 스크립트를 신고하세요.
// ==UserScript==
// @name Fextralife Searchbox Focus
// @version 1.0
// @author Tsusho
// @description Target the searchbox on Fextralife wikis with a hotkey
// @match https://*.wiki.fextralife.com/*
// @license MIT
// @grant none
// @namespace https://greasyfork.org/users/886069
// ==/UserScript==

let MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
let listener;
let observer = new MutationObserver(observer => {
    let searchbox = document.querySelector('#spf.form-control');
      console.log(searchbox);
      if (!listener) {
      listener = (function(){
        document.addEventListener('keydown', function(e) {
          // pressed alt+shift+f
          if (e.keyCode == 70 && e.shiftKey && !e.ctrlKey && e.altKey && !e.metaKey) {
            e.preventDefault();
            searchbox.focus();
          }
        }, false);
      })();
    }

});
observer.observe(document.body, {childList: true, subtree: true});