imgur scroll to gallery images keyboard shortcuts

use ./, 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.1
  5. // @description use ./, 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
  12.  
  13. var current = 0;
  14. var elems = $('div.image');
  15. var numElems = elems.length;
  16.  
  17. $(document).on('keypress', function (key) {
  18. if (key.which == 46) {
  19. if (current + 1 == numElems) {
  20. if ($('div#album-truncated')) {
  21. $('div#album-truncated > a').click();
  22. elems = $('div.image');
  23. numElems = elems.length;
  24. }
  25. return;
  26. }
  27. elems[current + 1].scrollIntoView();
  28. $('body').scrollTop($('body').scrollTop() - 10);
  29. current = current + 1;
  30. }
  31. if (key.which == 44) {
  32. if (current == 0) {
  33. return;
  34. }
  35. elems[current - 1].scrollIntoView();
  36. $('body').scrollTop($('body').scrollTop() - 10);
  37. current = current - 1;
  38. }
  39. });