Google search box auto-focus

Always set input focus to the search textbox

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

You will need to install an extension such as Tampermonkey to install this script.

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Google search box auto-focus
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Always set input focus to the search textbox
// @author       Matt Blais
// @include     http*://www.google.*/*
// @exclude     http*://www.google.com/recaptcha/*
// @include     http*://www.google.co*.*/*
// @include     http*://news.google.*/*
// @include     http*://encrypted.google.*/*
// @grant        none
// ==/UserScript==

// Focus the search box whenever the page becomes active/focused
(function() {
    'use strict'
	var fo = function ()
    {
		var inp = document.getElementsByTagName("input")
		if( inp && inp.length > 2 ) {
			inp[2].focus()
            // Select all text in box
            inp[2].select()
			// Collapse the search combobox
		    var cbdd = document.getElementsByClassName('UUbT9')
            if (cbdd.length) {
		    	window.setTimeout(function() { cbdd[0].style.display = 'none' }, 20)
            }
		}
	}

	window.addEventListener('focus', fo)
	fo()

}() )