Skip to content

Instantly share code, notes, and snippets.

@channprj
Last active August 4, 2017 12:51
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 channprj/58eb36f2bb4c75ad8c8dcc2e002c3f1f to your computer and use it in GitHub Desktop.
Save channprj/58eb36f2bb4c75ad8c8dcc2e002c3f1f to your computer and use it in GitHub Desktop.
Google Custom Shortcuts
// ==UserScript==
// @name Add Keyboard shortcuts for Google Search
// @namespace CHANN
// @description Adds '/' key as shortcut for accessing Google search bar
// @include https://www.google.*
// @version 0.1
// @grant none
// ==/UserScript==
window.addEventListener("keyup", function(event) {
if (event.code == "Slash") {
document.getElementById("lst-ib").focus();
document.getElementById("lst-ib").select();
// setCaretPosition("lst-ib");
}
}, true);
// function setCaretPosition(elemId, caretPos) {
// var elem = document.getElementById(elemId);
// if(elem !== null) {
// if(elem.createTextRange) {
// var range = elem.createTextRange();
// range.move('character', caretPos);
// range.select();
// }
// else {
// if(elem.selectionStart) {
// elem.focus();
// elem.setSelectionRange(caretPos, caretPos);
// }
// else
// elem.focus();
// }
// }
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment