Last active
August 4, 2017 12:51
-
-
Save channprj/58eb36f2bb4c75ad8c8dcc2e002c3f1f to your computer and use it in GitHub Desktop.
Google Custom Shortcuts
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 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