Skip to content

Instantly share code, notes, and snippets.

@caspark
Created January 19, 2020 22:26
Show Gist options
  • Save caspark/cb561ce60629dd70ee7533af54828379 to your computer and use it in GitHub Desktop.
Save caspark/cb561ce60629dd70ee7533af54828379 to your computer and use it in GitHub Desktop.
Google slash search
// ==UserScript==
// @name Google Slash Search
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://www.google.com/search*
// @grant none
// ==/UserScript==
(function() {
'use strict';
window.addEventListener("keypress", e => {
if (e.key == "/") {
const searchField = document.querySelector('#searchform input[type="text"]');
searchField.focus();
searchField.setSelectionRange(0, searchField.value.length);
e.preventDefault();
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment