Created
September 28, 2014 06:53
-
-
Save tdaitx/4d53a87964d128f4c047 to your computer and use it in GitHub Desktop.
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
var nextImage = function(img) { | |
if (img.nextSibling) return img.nextSibling.nextSibling; | |
return null; | |
}; | |
var previousImage = function(img) { | |
if (img.previousSibling) return img.previousSibling.previousSibling; | |
return null; | |
}; | |
var hideImage = function(img) { | |
img.style.display='none'; | |
img.nextSibling.style.display='none'; | |
}; | |
var showImage = function(img) { | |
img.style.display='inline'; | |
img.nextSibling.style.display='inline'; | |
}; | |
var manga_video_images = document.querySelectorAll('DIV#content > DIV > IMG'); | |
showImage(manga_video_images[0]); | |
for (idx = 1; idx < manga_video_images.length; ++idx) | |
hideImage(manga_video_images[idx]); | |
var checkShortcuts = function(event) { | |
switch(event.keyCode){ | |
case 37: // left arrow | |
case 74: // j | |
current_image = document.querySelector('DIV#content > DIV > IMG[style*=\'display: inline\']'); | |
previous_image = previousImage(current_image); | |
if (previous_image) { | |
hideImage(current_image); | |
showImage(previous_image); | |
event.stopPropagation(); | |
event.stop(); | |
event.preventDefault(); | |
} else { | |
Hotkeys.keydown(event); | |
} | |
break; | |
case 39: // right arrow | |
case 75: // k | |
current_image = document.querySelector('DIV#content > DIV > IMG[style*=\'display: inline\']'); | |
next_image = nextImage(current_image); | |
if (next_image) { | |
hideImage(current_image); | |
showImage(next_image); | |
event.stopPropagation(); | |
event.stop(); | |
event.preventDefault(); | |
} else { | |
Hotkeys.keydown(event); | |
} | |
break; | |
default: | |
break; | |
} | |
}; | |
Event.stopObserving(document, 'keydown'); | |
Event.observe(document, 'keydown', checkShortcuts); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment