APUG.org show image keyboard control

Keyboard navigation for APUG user gallery images.

  1. // ==UserScript==
  2. // @name APUG.org show image keyboard control
  3. // @namespace http://oscar.carlsson.photography/
  4. // @description Keyboard navigation for APUG user gallery images.
  5. // @include http://www.apug.org/gallery1/showimage.php?i=*
  6. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js
  7. // @version 1
  8. // @grant none
  9. // ==/UserScript==
  10. function find_links() {
  11. links = {};
  12. $('div.smallfont a').each(function (e) {
  13. if ($(this) [0].textContent === 'Previous Image')
  14. links.prev = $(this) [0];
  15.  
  16. if ($(this) [0].textContent === 'Next Image')
  17. links.next = $(this) [0];
  18. });
  19. return links;
  20. }
  21.  
  22. function upwards() {
  23. var breadcrumbs = $('div#breadcrumb li.navbit'),
  24. previous = null;
  25. for (var index = 0; index < breadcrumbs.length; index++) {
  26. var breadcrumb = breadcrumbs[index],
  27. classes = breadcrumb.className.split(/\s+/);
  28. if ($.inArray('lastnavbit', classes) === - 1) {
  29. previous = breadcrumb;
  30. continue;
  31. } else {
  32. // fetch link from the previous element
  33. var children = $(previous).children();
  34. for (var idx = 0; idx < children.length; idx++) {
  35. var child = children[idx],
  36. url = child.href;
  37. if (url) window.location.assign(url);
  38. }
  39. }
  40. }
  41. }
  42.  
  43. $(window).keyup(function (e) {
  44. var key = e.keyCode;
  45.  
  46. if (key == 39 || key == 37)
  47. var links = find_links();
  48.  
  49. if (key == 37) {
  50. window.location.assign(links.prev.href);
  51. return;
  52. }
  53. if (key == 39) {
  54. window.location.assign(links.next.href);
  55. return;
  56. }
  57. if (key == 85) { // u
  58. upwards();
  59. return;
  60. }
  61. });