Skip to content

Commit

Permalink
リファクタリング&楽天注文履歴ページのセレクタ修正
Browse files Browse the repository at this point in the history
  • Loading branch information
kawaz committed Jan 17, 2015
1 parent 5b6dbea commit 12aaf22
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
41 changes: 29 additions & 12 deletions document_start.js
@@ -1,19 +1,36 @@
[ {url:/^https?:\/\/www.google.(.*)\/search/, selector:"input[name=q]"}
, {url:/^http:\/\/search.books.rakuten.co.jp\//, selector:"#searchWords"}
, {url:/^https:\/\/order.my.rakuten.co.jp\//, selector:"input[name=search_item]"}
, {url:/^https?:\/\/search.books.rakuten.co.jp\//, selector:"#searchWords"}
, {url:/^https?:\/\/order.my.rakuten.co.jp\//, selector:"#inputSearch"}
, {url:/^http:\/\/[\w\.]+\.alc.co.jp\//, selector:"#q"}
].forEach(function(o){
if(o.url.test(location.href)) {
addFocusTarget(o.selector);
}
if(o.url.test(location.href)) {
addFocusTarget(o.selector);
}
});
function addFocusTarget(selector) {
//ページ読み込み
document.addEventListener("DOMContentLoaded", function(){
var elm = document.querySelector(selector);
if(elm) {
//初回自動フォーカス
elm.focus();
elm.select();
//貼付け時自動検索追加
elm.addEventListener('paste', function(e){
setTimeout(function(){
elm.form && elm.form.submit();
}, 0);
});
}
}, false);
//タブ移動時自動フォーカス
document.addEventListener("webkitvisibilitychange", function(){
if("visible" == document.webkitVisibilityState) {
var elm = document.querySelector(selector);
if(elm) {
elm.focus();
elm.select();
}
if("visible" == document.webkitVisibilityState) {
var elm = document.querySelector(selector);
if(elm) {
elm.focus();
elm.select();
}
}, false);
}
});
}
3 changes: 2 additions & 1 deletion manifest.json
Expand Up @@ -2,7 +2,8 @@
, "name": "__MSG_extName__"
, "description": "__MSG_extDescription__"
, "default_locale": "en"
, "version": "0.0.1"
, "version": "0.0.4"
, "permissions": [ "http://*/*", "https://*/*" ]
, "content_scripts":
[ { "all_frames": false
, "js": [ "document_start.js" ]
Expand Down

0 comments on commit 12aaf22

Please sign in to comment.