ORSM Gallery Keybindings

Navigate trough orsm.net galleries with the arrow keys

  1. // ==UserScript==
  2. // @name ORSM Gallery Keybindings
  3. // @name:de ORSM Cursornavigation
  4. // @namespace http://tampermonkey.net/
  5. // @version 0.1
  6. // @description Navigate trough orsm.net galleries with the arrow keys
  7. // @description:de Navigation mittels Cursortasten durch die orsm.net Gallerien
  8. // @author You
  9. // @match http*://www.orsm.net/i/gallery/*
  10. // @require https://code.jquery.com/jquery-3.3.1.min.js
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. var next = 0;
  15. var prev = 0;
  16.  
  17. (function() {
  18. 'use strict';
  19. if (window.top != window.self) { //-- Don't run on frames or iframes.
  20. return;
  21. }
  22. document.onkeydown = checkKey;
  23. window.onload = function () {
  24. document.getElementById("bigimg").scrollIntoView({block: "end", inline: "center"});
  25.  
  26. var links = document.links;
  27. for(var i=0; i<links.length; i++) {
  28. if(links[i].innerHTML.valueOf() == "Next &gt;&gt;&gt;") {
  29. next = links[i].href;
  30. } else if(links[i].innerHTML.valueOf() == "&lt;&lt;&lt; Prev") {
  31. prev = links[i].href;
  32. }
  33. }
  34. }
  35. }
  36. )();
  37.  
  38. function checkKey(e) {
  39. var links = document.links;
  40. for(var i=0; i<links.length; i++) {
  41. if(links[i].innerHTML.valueOf() == "Next &gt;&gt;&gt;") {
  42. next = links[i].href;
  43. } else if(links[i].innerHTML.valueOf() == "&lt;&lt;&lt; Prev") {
  44. prev = links[i].href;
  45. }
  46. }
  47. e = e || window.event;
  48. if (e.keyCode == '37') {
  49. if (prev.length > 0) {
  50. window.open(prev, "_self");
  51. }
  52. }
  53. else if (e.keyCode == '39') {
  54. if (next.length > 0) {
  55. window.open(next, "_self");
  56. }
  57. }
  58.  
  59. }