Auto Focus

Auto Focus on load.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name           Auto Focus
// @description:en Auto Focus on load.
// @version        1.0
// @namespace      http//example.com
// @include        *
// @description Auto Focus on load.
// ==/UserScript==
(function(){
    var d = document;
    
    var settings = [
        // はてなブックマーク
        {
            site: "b.hatena.ne.jp",
            find: function(){
                var helper = function(id){
                    var f = d.getElementById(id);
                    return f && f.getElementsByTagName("input")[0];
                }
                
                return helper("tag-search-related-form") ||
                       helper("tag-search-form");
            }
        }
    ];
    
    for(var i = 0, n = settings.length; i < n; i++){
        var setting = settings[i];
        var regex = getRegex(setting.site);
        if(location.href.match(regex)){
            var found = setting.find();
            found && found.focus();
        }
    }
    
    function getRegex(s){
        s = s.replace(".", "\\.");
        s = s.replace("*", ".*");
        s = s.replace("?", "\\?");
        s = s.replace("/", "\\/");
        s = "^http:\\/\\/" + s;
        return new RegExp(s, "i");
    }
})();