Skip to content

Instantly share code, notes, and snippets.

@eyy
Last active August 29, 2015 13:55
Show Gist options
  • Save eyy/8696014 to your computer and use it in GitHub Desktop.
Save eyy/8696014 to your computer and use it in GitHub Desktop.
Bookmarklet: Jump to next image (J)
javascript:(function() { var i = 0; function nextImg() { var imgs = document.querySelectorAll('img'), el; while (i < imgs.length) { el = imgs[i]; i++; if (el.getBoundingClientRect().top > 0) { return el.scrollIntoView(); } } i = 0; } document.addEventListener('keypress', function(e) { var key = String.fromCharCode(e.keyCode || e.which); if (key == 'j') nextImg(); }); nextImg(); })();
(function() {
var i = 0;
function nextImg() {
var imgs = document.querySelectorAll('img'),
el;
while (i < imgs.length) {
el = imgs[i];
i++;
if (el.getBoundingClientRect().top > 0) {
return el.scrollIntoView();
}
}
i = 0;
}
document.addEventListener('keypress', function(e) {
var key = String.fromCharCode(e.keyCode || e.which);
if (key == 'j')
nextImg();
});
nextImg();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment