Skip to content

Instantly share code, notes, and snippets.

@eggbean
Last active October 6, 2021 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eggbean/ba4daf82f132421c69dbd2c2e0b3e061 to your computer and use it in GitHub Desktop.
Save eggbean/ba4daf82f132421c69dbd2c2e0b3e061 to your computer and use it in GitHub Desktop.
Userscript for Twitter Go Back with H key
// ==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;
}
}
});
})();
@eggbean
Copy link
Author

eggbean commented Oct 6, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment