Last active
April 20, 2022 18:25
-
-
Save thmsmlr/352d9a346671859ecb24b7afcceab958 to your computer and use it in GitHub Desktop.
[Tampermonkey] Google VIM Hotkeys
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 Google VIM Hotkeys | |
// @namespace https://gist.github.com/ccjmne | |
// @version 0.0.1 | |
// @description Navigate results from Google using j/k vim bindings | |
// @author Thomas Millar <[email protected]> (https://github.com/thmsmlr) | |
// @match *://www.google.com/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
var style = document.createElement('style'); | |
style.innerHTML = ` | |
a:focus { | |
outline: 2px solid !important; | |
} | |
`; | |
document.head.appendChild(style); | |
var idx = -1; | |
var getSearchResults = () => Array.from(document.querySelectorAll('#rso > div:not(.ULSxyf) a > h3')).map(x => x.parentNode) | |
// Your code here... | |
document.addEventListener('keydown', function(e) { | |
if(e.key === 'j') { | |
idx += 1; | |
let elem = getSearchResults()[idx] | |
elem.focus(); | |
} else if(e.key === 'k') { | |
idx -= 1; | |
let elem = getSearchResults()[idx] | |
elem.focus(); | |
} | |
}) | |
console.log('Shortcuts loaded'); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment