Skip to content

Instantly share code, notes, and snippets.

@KargJonas
Last active November 2, 2025 13:30
Show Gist options
  • Select an option

  • Save KargJonas/a9e32206145b3138d67746027125caee to your computer and use it in GitHub Desktop.

Select an option

Save KargJonas/a9e32206145b3138d67746027125caee to your computer and use it in GitHub Desktop.
ViolentMonkey script for focussing search bars when you press tab.
// ==UserScript==
// @name Focus Search on Tab
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Focus the main search input when Tab is pressed
// @match *://*/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
document.addEventListener('keydown', (e) => {
// Only trigger on Tab, and only if we're not already in an input/textarea
if (e.key !== 'Tab') return;
// Find search input with a simple heuristic
const selectors = [
'input[type="search"]',
'input[name*="search" i]',
'input[name*="query" i]',
'input[id*="search" i]',
'input[placeholder*="search" i]',
'input[aria-label*="search" i]',
'input[type="text"]',
'div#prompt-textarea',
'textarea',
'*[contenteditable="true"]',
];
const inputs = document.querySelectorAll(selectors.join(','));
// Find first visible input
for (let input of inputs) {
if (input.offsetParent !== null && !input.disabled) {
e.preventDefault();
input.focus();
return;
}
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment