Google search box auto-focus

Always set input focus to the search textbox

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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()

}() )