imgur scroll to gallery images keyboard shortcuts

use up/down arrow to scroll to the next/previous image within an imgur gallery

当前为 2015-06-13 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name imgur scroll to gallery images keyboard shortcuts
  3. // @namespace http://porath.org/
  4. // @version 0.11
  5. // @description use up/down arrow to scroll to the next/previous image within an imgur gallery
  6. // @author porath
  7. // @match http://imgur.com/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. // thanks to moiph and CBenni and Brybry
  12.  
  13. var current = 0;
  14. var elems = $('div.image');
  15. var numElems = elems.length;
  16.  
  17. $(document).on('keydown', function (key) {
  18. if (key.which == 40) {
  19. key.preventDefault();
  20. if (current + 1 == numElems) {
  21. if ($('div#album-truncated')) {
  22. $('div#album-truncated > a').click();
  23. elems = $('div.image');
  24. numElems = elems.length;
  25. }
  26. return;
  27. }
  28. elems[current + 1].scrollIntoView();
  29. $('body').scrollTop($('body').scrollTop() - 10);
  30. current = current + 1;
  31. }
  32. if (key.which == 38) {
  33. key.preventDefault();
  34. if (current == 0) {
  35. return;
  36. }
  37. elems[current - 1].scrollIntoView();
  38. $('body').scrollTop($('body').scrollTop() - 10);
  39. current = current - 1;
  40. }
  41. });