Greasy Fork is available in English.

Focus Input Keybind

Focus to search or a certain text input with forward slash (/) key similar to YouTube.

질문, 리뷰하거나, 이 스크립트를 신고하세요.
  1. // ==UserScript==
  2. // @name Focus Input Keybind
  3. // @namespace https://github.com/kittenparry/
  4. // @version 1.7
  5. // @description Focus to search or a certain text input with forward slash (/) key similar to YouTube.
  6. // @author kittenparry
  7. // @match *://*/*
  8. // @grant none
  9. // @license GPL-3.0-or-later
  10. // ==/UserScript==
  11.  
  12. /* LIST:
  13. * *.booru.org
  14. * camwhores.tv
  15. * instagram.com/direct/
  16. * jisho.org
  17. * metal-tracker.com
  18. * nyaa.si
  19. * rarbg.to || rarbg2020.org || rarbgget.org
  20. * reddit.com
  21. * twitch.tv
  22. * wiktionary.org
  23. * youtube.com
  24. */
  25.  
  26. /* CHANGELOG:
  27. * 1.7: +youtube.com | i guess we've come full circle
  28. * 1.6.1: +rarbgget.org (rarbg.to alternative)
  29. * 1.6: +camwhores.tv
  30. * 1.5: +jisho.org
  31. * 1.4.1: +rarbg2020.org (rarbg.to alternative)
  32. * 1.4: +nyaa.si +instagram.com/direct/
  33. * 1.3: +metal-tracker.com
  34. * 1.2: +*.booru.org
  35. * 1.1: +wiktionary.org
  36. * 1.0: initial
  37. */
  38.  
  39. check_focus_input_keybind = (e, val, special) => {
  40. var type = e.target.getAttribute('type');
  41. var tag = e.target.tagName.toLowerCase();
  42. if (type != 'text' && tag != 'textarea') {
  43. if (e.keyCode == 191) { // /
  44. if (special == 'reddit') {
  45. document.getElementById(val).firstChild.focus();
  46. } else if (special == 'instagram') {
  47. document.querySelector(val).firstChild.focus()
  48. } else if (special == 'selector') {
  49. document.querySelector(val).focus();
  50. } else {
  51. document.getElementById(val).focus();
  52. }
  53. }
  54. }
  55. };
  56.  
  57. /* probably need a better way than simply .includes()
  58. * inid: id or other value of the input element
  59. * inspcl: when inid isn't an id (eg. a class) to specify it
  60. */
  61.  
  62. var current_url = window.location.href;
  63.  
  64. if (current_url.includes('.booru.org')) {
  65. var inid = 'tags';
  66. } else if (current_url.includes('camwhores.tv')) {
  67. var inid = 'input[name="q"]';
  68. var inspcl = 'selector';
  69. } else if (current_url.includes('instagram.com/direct/')) {
  70. var inid = 'div[class=" Igw0E IwRSH eGOV_ vwCYk ItkAi "]';
  71. var inspcl = 'instagram';
  72. } else if (current_url.includes('jisho.org')) {
  73. var inid = 'keyword';
  74. } else if (current_url.includes('metal-tracker.com')) {
  75. var inid = 'searchBox';
  76. } else if (current_url.includes('nyaa.si')) {
  77. var inid = 'input[class="form-control search-bar"]';
  78. var inspcl = 'selector';
  79. } else if (current_url.includes('rarbg.to') || current_url.includes('rarbg2020.org') || current_url.includes('rarbgget.org')) {
  80. var inid = 'searchinput';
  81. } else if (current_url.includes('reddit.com')) {
  82. var inid = 'search';
  83. var inspcl = 'reddit';
  84. } else if (current_url.includes('twitch.tv')) {
  85. var inid = 'textarea[class="tw-block tw-border-radius-medium tw-font-size-6 tw-full-width tw-textarea tw-textarea--no-resize"]';
  86. var inspcl = 'selector';
  87. } else if (current_url.includes('wiktionary.org')) {
  88. var inid = 'searchInput';
  89. } else if (current_url.includes('youtube.com')) {
  90. var inid = 'input[name="search_query"]';
  91. var inspcl = 'selector';
  92. }
  93.  
  94. if (inid != undefined) {
  95. try {
  96. // pass an empty string for input special so to not repeat the event listener code similar to other script
  97. if (!inspcl) {
  98. var inspcl = '';
  99. }
  100. // keyup instead of keydown to prevent the initial entry of a forward slash to input
  101. window.addEventListener('keyup', (e) => check_focus_input_keybind(e, inid, inspcl), false);
  102. } catch (e) {}
  103. }