Created
August 29, 2018 03:05
-
-
Save m5/247631d8258ff6f52383b417acd8516f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Duck Duck Go insta-bang | |
// @description Hitting "g" focuses search and appends an ! | |
// @include https://www.duckduckgo.com/* | |
// @include https://duckduckgo.com/* | |
// @include http://duckduckgo.com/* | |
// ==/UserScript== | |
(function(){ | |
var searchBox = document.getElementById("search_form_input") | |
|| document.getElementById("search_form_input_homepage"); | |
document.addEventListener( 'keydown', function(e){ | |
switch(e.keyCode){ | |
case 71: | |
if(document.activeElement !== searchBox){ | |
searchBox.value = searchBox.value + " !"; | |
var len = searchBox.value.length; | |
searchBox.setSelectionRange(len, len); | |
searchBox.focus(); | |
e.stopPropagation(); | |
e.preventDefault(); | |
} | |
break; | |
} | |
}, false); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment