NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript==
// @name Search field quick interaction.
// @namespace searchInputs
// @description 1. When you go to the websites, included into this file through @include 'website name' lines below - focus on search field instantly.
// 2. On "alt" (event.keyCode === 18) click - unfocus. Change the unfocus triggering button by choosing the keyCodes on this page:
// https://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes
// and substituting the number 18 in the code with the one that you found on the page above.
// 3.
// @include https://en.wikipedia.org/wiki/*
// @include http://www.ldoceonline.com/*
// @include https://translate.google.com/*
// @include http://www.thesaurus.com/*
// @version 1.1
// @author LAITONEN
// V1.01 added functionality on accessing any wikipedia page, not only the main one
// V1.02 added 2nd row with the focusing on the search input with a different id or class name
// V1.1 added functionality to unfocus the search field on button click;
// included http://www.thesaurus.com/*
// ==/UserScript==
if (document.getElementById('searchInput'))
{
var element = document.getElementById('searchInput');
element.addEventListener('keydown', function(){
if(event.keyCode === 18){
document.getElementById('searchInput').blur();
}
});
element.focus();
}
else if (document.querySelector('.search_input'))
{
var element = document.querySelector('.search_input');
element.addEventListener('keydown', function(){
if(event.keyCode === 18){
document.querySelector('.search_input').blur();
}
});
element.focus();
}
else if (document.getElementById('source'))
{
var element = document.getElementById('source');
element.addEventListener('keydown', function(){
if(event.keyCode === 18){
document.getElementById('source').blur();
}
});
element.focus();
}
else if (document.getElementById('q'))
{
var element = document.getElementById('q');
element.addEventListener('keydown', function(){
if(event.keyCode === 18){
document.getElementById('q').blur();
}
});
element.focus();
}