Skip to content

Instantly share code, notes, and snippets.

@TikiTDO
Last active June 8, 2016 22:26
Show Gist options
  • Save TikiTDO/f2e29f272279cbffdf78578c3176a1d5 to your computer and use it in GitHub Desktop.
Save TikiTDO/f2e29f272279cbffdf78578c3176a1d5 to your computer and use it in GitHub Desktop.
Arrow navigator for http://www.starpowercomic.com/
(function () {
// Do nothing if mouse events are not supported
if (!MouseEvent) return;
// Init
var LEFT_KEY = 37;
var RIGHT_KEY = 39;
// Click event for the back button
var click_event = new MouseEvent('click', {view: window, bubbles: true, cancelable: true});
// Listen for keyboard presses
document.addEventListener("keydown", function (event) {
var to_click = null;
// Detect right and left keys
if(event.keyCode == LEFT_KEY)
to_click = document.getElementsByClassName('navi-prev')[0];
else if (event.keyCode == RIGHT_KEY)
to_click = document.getElementsByClassName('navi-next')[0];
// Click if necessary
if(to_click)
to_click.dispatchEvent(click_event);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment