slash search bar focus

Focus search bar on pressing SLASH (/) or BACKSLASH (\) on amazon.de, bing.com, userscript.zone, github, aliexpress, hornbach, readly, greasyfork, ebay, temu

  1. // ==UserScript==
  2. // @name slash search bar focus
  3. // @namespace guebosch
  4. // @version 2025-03-06
  5. // @description Focus search bar on pressing SLASH (/) or BACKSLASH (\) on amazon.de, bing.com, userscript.zone, github, aliexpress, hornbach, readly, greasyfork, ebay, temu
  6. // @author guebosch
  7. // @match https://www.bing.com/search*
  8. // @match https://www.userscript.zone/search*
  9. // @match https://github.com/*
  10. // @match https://go.readly.com/*
  11. // @match https://gf.qytechs.cn/en/scripts*
  12. // @match https://www.hornbach.at/*
  13. // @match https://*.aliexpress.com/*
  14. // @match https://*.temu.com/*
  15. // @match https://www.amazon.de/*
  16. // @match https://www.google.com/search?q=*
  17. // @match https://www.google.com/search?newwindow=*
  18. // @match https://www.ebay.at/sch/*
  19. // @match https://www.ebay.de/sch/*
  20. // @match https://www.reddit.com/*
  21. // @match https://www.ebay.com/sch/*
  22. // @match https://piratehaven.xyz/search.php?*
  23. // @icon https://www.google.com/s2/favicons?sz=64&domain=bing.com
  24. // @grant none
  25. // ==/UserScript==
  26.  
  27. //debugger;
  28.  
  29. // Note: google seems to work out of the box. somethimes. Not always on the News Page.
  30.  
  31. (function() {
  32. const hostname = window.location.hostname;
  33. var searchField;
  34. window.addEventListener("keypress", e => {
  35. if (['TEXTAREA', 'INPUT'].includes(e.target.nodeName)) return;
  36. if (e.key !== "/" && e.key !== "\\") return;
  37.  
  38. if (['www.bing.com', 'www.hornbach.at'].includes(hostname)) {
  39. searchField = document.querySelector('textarea[type="search"], input[type="search"], input[name="search"], input[placeholder*="Search"]');
  40. }
  41. else if (['www.userscript.zone','piratehaven.xyz'].includes(hostname)) {
  42. searchField = document.querySelector('#search');
  43. }
  44. else if (['github.com'].includes(hostname)) {
  45. searchField = document.querySelector('#js-issues-search');
  46. }
  47. else if (['de.aliexpress.com','en.aliexpress.com','www.aliexpress.com'].includes(hostname)) {
  48. searchField = document.querySelector('#search-words');
  49. }
  50. else if (['www.amazon.de'].includes(hostname)) {
  51. searchField = document.querySelector('#twotabsearchtextbox');
  52. }
  53. else if (['go.readly.com'].includes(hostname)) {
  54. searchField = document.querySelector('#content-gate-input');
  55. }
  56. else if (['gf.qytechs.cn'].includes(hostname)) {
  57. searchField = document.querySelector('input[type="search"][name="q"]');
  58. }
  59. else if (['reddit.com'].includes(hostname)) {
  60. searchField = document.querySelector('input[type="text"][name="q"]');
  61. }
  62. else if (['www.ebay.at','www.ebay.de','www.ebay.com'].includes(hostname)) {
  63. searchField = document.querySelector('#gh-ac');
  64. }
  65. else if (['www.google.com'].includes(hostname)) {
  66. searchField = document.querySelector('#textarea[name="q"], textarea[id="q"]');
  67. }
  68. else if (['www.temu.com'].includes(hostname)) {
  69. searchField = document.querySelector('input[id="searchInput"]');
  70. }
  71. if (!searchField) return;
  72. window.scrollTo(0, 0); // Scroll to the top
  73. searchField.focus();
  74. // move cursor to the right
  75. searchField.setSelectionRange(searchField.value.length, searchField.value.length);
  76. e.preventDefault();
  77. });
  78. })();

QingJ © 2025

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