NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name Search fields' focus / unfocus // @namespace searchInputs // @description Auto-focus on the search / input fields of the specified website. By default (wikipedia, ldoceonline, translate.google.com, thesaurus.com). // @features // 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. // @beforeTheUse 1. Substitute the below-included websites links with the ones that you oftenly use. // Do not forget: 1. Add star sign (*) at the end of the url; 2. If the script will not be working, find out the id / class name of the seacrh / input // field on your website (for example, through 'inspect' feature of Chrome) and modify the if-statement blocks accordingly. // @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== // https://en.wikipedia.org/wiki/ if (document.getElementById('searchInput')) { var element = document.getElementById('searchInput'); element.addEventListener('keydown', function(){ if(event.keyCode === 18){ document.getElementById('searchInput').blur(); } }); element.focus(); } // http://www.ldoceonline.com/* 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(); } // https://translate.google.com/* else if (document.getElementById('source')) { var element = document.getElementById('source'); element.addEventListener('keydown', function(){ if(event.keyCode === 18){ document.getElementById('source').blur(); } }); element.focus(); } // http://www.thesaurus.com/* else if (document.getElementById('q')) { var element = document.getElementById('q'); element.addEventListener('keydown', function(){ if(event.keyCode === 18){ document.getElementById('q').blur(); } }); element.focus(); }