mtdtks
6/28/2015 - 7:55 AM

amazon_focus2searchbar

amazon_focus2searchbar

// ==UserScript==
// @name amazon_focus2serchbar
// @namespace mtdtks
// @version 0.0.1.2
// @description everytime focus amazon's searchbar
// @author mtdtks
// @include http://www.amazon.co.jp/s/*
// @include http://www.amazon.co.jp/d/*
// @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==
//##System requirements
//##chrome 44.02
//##firefox33 with vimperator

//##firefox settings##
//##if use with firefox, delete comment out next line.
//##content.focus();

//##ToDo
//後日「詳細検索」「トップ」URLを除外する。


var userAgent = window.navigator.userAgent.toLowerCase();
var browserName
if (userAgent.indexOf('chrome') != -1) {
  browserName='chrome';
} else if (userAgent.indexOf('firefox') != -1) {
  browserName='firefox';
} else {
  return false;
}

//##for firefox setting
function focusContent(){
    if(browserName === 'firefox'){
        content.focus();
        //debug
        //alert('fire!');
    }
}


$(document).ready(function(){
  (function(){
    //##for firefox
    focusContent();
    $('input:visible').eq(1).select();
  })();
});
//エンターで強制リロードして選択させる
function reLoad(){
  setTimeout(function(){
    location.reload();
  },100);
}

$("body").keypress( function( event ) {
  if( event.which === 13 ){
  var id = $(':focus').attr("id");
  //test
  //alert(id);
  if(id == "twotabsearchtextbox"){
    reLoad();
    //##for firefox
    focusContent();
    $('input:visible').eq(1).select();
  }
}
});


//todo後日「詳細検索」「トップ」URLを除外する。
/*
    let elem = document.commandDispatcher.focusedElement;
    if (elem) elem.blur();

    gBrowser.focus();
    _content.focus();
*/

/*
$(document).ready(function(){
  (function(){
   $('input:visible').eq(0).select();
  }
  )();
});
//エンターで強制リロードして選択させる
function reLoad(){
setTimeout(function(){
location.reload();
},100);
}
//後日「詳細検索」「トップ」URLを除外する。
$("body").keypress( function( event ) {
if( event.which === 13 ){
var id = $(':focus').attr("id");
//test
//alert(id);
if(id == "twotabsearchtextbox"){
reLoad();
}
}
});
*/
///////test集///////
/*これも2回目以降動かない
window.onload = function(){
alert('javascript2');
}
*/
//$("input:checkbox").attr("checked",false);
//$("option").attr("selected",false);
//これは出来る
//これはフォーカスできない
//$('#twotabsearchtextbox').eq(1).blur();
//これはできる
//$('input:visible').eq(1).select();
//test
//var id = $(':focus').attr("id");
//alert(id);
/* だめ
setTimeout(function(){
$('input:visible').eq(1).select();
}, 0);
*/
/*
$("body").keypress( function( event ) {
if( event.which === 13 ){
var re = "twotabsearchtextbox";
var id = $(':focus').attr("id");
if(re.test(id)){
reLoad();
}
}
});
*/