Last active
October 6, 2021 20:19
-
-
Save eggbean/ba4daf82f132421c69dbd2c2e0b3e061 to your computer and use it in GitHub Desktop.
Userscript for Twitter Go Back with H key
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 Twitter Go Back with H key | |
// @namespace https://gist.github.com/eggbean/ba4daf82f132421c69dbd2c2e0b3e061/raw/twitter_go_back.user.js | |
// @version 1.0 | |
// @description Makes the unused H key a browser back button for better H,J,K,L keyboard navigation | |
// @author https://github.com/eggbean | |
// @match https://twitter.com/* | |
// @icon https://twitter.com/favicon.ico | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
var gKeyPressed = false; | |
addEventListener("keydown", function(e){ | |
if (document.activeElement.tagName != 'INPUT' && document.activeElement.tagName != 'TEXTAREA' && document.activeElement.contentEditable != 'true') { | |
switch (e.keyCode) { | |
case 71: //"g" | |
gKeyPressed = true; | |
break; | |
case 72: //"h" | |
if (e.keyCode === 72 && gKeyPressed === false) { | |
history.back(); | |
} | |
break; | |
default: | |
gKeyPressed = false; | |
break; | |
} | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This userscript makes the unused H key into a Back key for better keyboard navigation. It works well but has a very minor problem where H won't work after using the standard G,H sequence (to go Home) until any other key is pressed.