Skip to content

Instantly share code, notes, and snippets.

@mtdtks
Last active August 29, 2015 14:23
Show Gist options
  • Save mtdtks/083f2a4b2879fc0124e5 to your computer and use it in GitHub Desktop.
Save mtdtks/083f2a4b2879fc0124e5 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name amazon_focus2searchbar_chrome
// @namespace http://your.homepage/
// @version 0.0.0.1
// @description everytime focus amazon's searchbar
// @author mtdtks
// @include http://www.amazon.co.jp/s/*
// @exclude http://www.amazon.co.jp/%E5%92%8C%E6%9B%B8%E8%A9%B3%E7%B4%B0%E3%82%B5%E3%83%BC%E3%83%81/b/ref=sv_b_0?ie=UTF8&node=124284011
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js
// @grant none
// ==/UserScript==
//なぜか2回目以降の検索だと動かない
$(document).ready(function(){
//$("input:checkbox").attr("checked",false);
//$("option").attr("selected",false);
//これは出来る
(function(){$('input:visible').eq(1).select();})();
//これはフォーカスできない
//$('#twotabsearchtextbox').eq(1).blur();
//これはできる
//$('input:visible').eq(1).select();
//test
//var id = $(':focus').attr("id");
//alert(id);
});
/*これも2回目以降動かない
window.onload = function(){
alert('javascript2');
}
*/
/* だめ
setTimeout(function(){
$('input:visible').eq(1).select();
}, 0);
*/
//エンターで強制リロードして選択させる
function reLoad(){
setTimeout(function(){
location.reload();
},100);
}
$("body").keypress( function( event ) {
if( event.which === 13 ){
//test
var id = $(':focus').attr("id");
//test
//alert(id);
if(id == "twotabsearchtextbox"){
reLoad();
}
}
});
/*
$("body").keypress( function( event ) {
if( event.which === 13 ){
var re = "twotabsearchtextbox";
var id = $(':focus').attr("id");
if(re.test(id)){
reLoad();
}
}
});
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment