Skip to content

Instantly share code, notes, and snippets.

@thmsmlr
Last active April 20, 2022 18:25
Show Gist options
  • Save thmsmlr/352d9a346671859ecb24b7afcceab958 to your computer and use it in GitHub Desktop.
Save thmsmlr/352d9a346671859ecb24b7afcceab958 to your computer and use it in GitHub Desktop.
[Tampermonkey] Google VIM Hotkeys
// ==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 <millar.thomas@gmail.com> (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