Keyboard navigation e621

Change the current page with arrow keys

  1. // ==UserScript==
  2. // @name Keyboard navigation e621
  3. // @version 0.2
  4. // @description Change the current page with arrow keys
  5. // @author koreso
  6. // @match https://e621.net/posts/*
  7. // @namespace https://greasyfork.org/users/510304
  8. // ==/UserScript==
  9.  
  10. (function() {
  11. 'use strict';
  12.  
  13. // check if a next or previous button exists on the current page
  14. if(document.querySelector(".next")||document.querySelector(".prev"))window.onkeydown = page;
  15.  
  16. function page(e) {
  17. // if the current focused element is a text box, abort
  18. if(document.activeElement.nodeName.match(/TEXTAREA|INPUT/))return;
  19.  
  20. // 39 = right arrow key, 37 = left arrow key
  21. switch(e.keyCode){
  22. case 39:
  23. // change current url to the next button's url
  24. window.location.assign(document.querySelector(".next"));
  25. break;
  26. case 37:
  27. // idem but for the previous button
  28. window.location.assign(document.querySelector(".prev"));
  29. break;
  30. }
  31. }
  32. })();