thealanberman / Amazon Search Tweaks

// ==UserScript==
// @name        Amazon Search Tweaks
// @namespace   https://gist.github.com/thealanberman/e8b902b8b19636a7c4b08afb93c46140
// @description Focus on search box on page load. Jump to search box via '/' key. Unfocus with Esc key.
// @include     http://amazon.*/
// @include     https://amazon.*/
// @include     http://*.amazon.*/
// @include     https://*.amazon.*/
// @require     https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js
// @version     1
// @copyright 2019, thealanberman (https://openuserjs.org/users/thealanberman)
// @license MIT
// ==/UserScript==

$(document).ready(function() {
    $("#twotabsearchtextbox").focus();
});

$(document).keyup(function(e) {
    e.preventDefault();
    // 191 = forward slash key
    if (e.keyCode == 191) {
        $("#twotabsearchtextbox").focus();
    }
});

$("#twotabsearchtextbox").keyup(function(e) {
    e.preventDefault();
    // 27 = esc key
    if (e.keyCode == 27) {
        $(this).blur();
    }
});