devdocs.io - Do not auto focus input

7/27/2024, 9:54:04 AM

  1. // ==UserScript==
  2. // @name devdocs.io - Do not auto focus input
  3. // @namespace Violentmonkey Scripts
  4. // @match https://devdocs.io/*
  5. // @grant none
  6. // @version 1.0
  7. // @author -
  8. // @license MIT
  9. // @description 7/27/2024, 9:54:04 AM
  10. // ==/UserScript==
  11.  
  12. const $input = document.querySelector('input[search]') ?? document.querySelector('input._search-input')
  13.  
  14. if ($input) {
  15. let allowFocus = false
  16. $input.addEventListener('mousedown', () => {
  17. allowFocus = true
  18. setTimeout(() => {
  19. allowFocus = false
  20. }, 0)
  21. })
  22. $input.addEventListener('keydown', () => {
  23. allowFocus = true
  24. setTimeout(() => {
  25. allowFocus = false
  26. }, 0)
  27. })
  28.  
  29. $input.addEventListener('focus', (e) => {
  30. if (!allowFocus) {
  31. e.target.blur()
  32. }
  33. allowFocus = false
  34. })
  35. }