Quick n' Dirty: Keyboard Navigation
I was recently on a comic website and was struggling heavily with their poor UI layout that made navigating pages quite painful so I wrote a tiny tampermonkey script to add in WASD style navigation. This particular site has both between issue and in-issue Previous/Next, so there is a “next page” and a “next comic” button.
For compatibility this is written as an ES5 IIFE with ye-olde dom events instead of some sexier DOM 3 tricks. Links are grabbed by text content which is expensive but this particular site didn’t have consistent classes or ids. I use focusin
and focusout
to make sure we aren’t in a textfield when navigating so you can still use search and whatnot (and it’s way cheaper/easier than patching every input with custom events and pretty well supported in most browsers).
For some potential upgrades, move to ES6, use compositionstart
and compositionend
, and use the new keyboard API instead of fighting keyCode.