-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAuto Focus.user.js
45 lines (41 loc) · 1.22 KB
/
Auto Focus.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// ==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");
}
})();