Skip to content

Instantly share code, notes, and snippets.

@m5
Created August 29, 2018 03:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m5/247631d8258ff6f52383b417acd8516f to your computer and use it in GitHub Desktop.
Save m5/247631d8258ff6f52383b417acd8516f to your computer and use it in GitHub Desktop.
// ==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