Sleazy Fork is available in English.

EH mpv - Keyboard Page Navigation

Jump between pages with keyboard shortcut

  1. // ==UserScript==
  2. // @name EH mpv - Keyboard Page Navigation
  3. // @namespace http://fabulous.cupcake.jp.net/
  4. // @version 20190206.3
  5. // @description Jump between pages with keyboard shortcut
  6. // @author FabulousCupcake
  7. // @match https://e-hentai.org/mpv/*
  8. // @match https://exhentai.org/mpv/*
  9. // @grant none
  10. // @run-at document-end
  11. // ==/UserScript==
  12.  
  13. const key = {
  14. LETTER_W: 87,
  15. LETTER_A: 65,
  16. LETTER_S: 83,
  17. LETTER_D: 68,
  18. ARROW_LEFT: 37,
  19. ARROW_UP: 38,
  20. ARROW_RIGHT: 39,
  21. ARROW_DOWN: 40,
  22. }
  23.  
  24. const jumpToPage = num => {
  25. const jumpTarget = document.getElementById(`image_${num}`);
  26. if (!jumpTarget) return;
  27.  
  28. jumpTarget.scrollIntoView();
  29. }
  30.  
  31. const jumpForward = () => jumpToPage(window.currentpage + 1);
  32. const jumpBack = () => jumpToPage(window.currentpage - 1);
  33.  
  34. const insertKeyBinds = () => {
  35. window.addEventListener('keydown', e => {
  36. const code = e.which || e.charCode || e.keyCode;
  37.  
  38. switch(code) {
  39. case key.ARROW_LEFT:
  40. case key.ARROW_UP:
  41. case key.LETTER_W:
  42. case key.LETTER_A:
  43. jumpBack();
  44. break;
  45.  
  46. case key.ARROW_RIGHT:
  47. case key.ARROW_DOWN:
  48. case key.LETTER_S:
  49. case key.LETTER_D:
  50. jumpForward();
  51. break;
  52.  
  53. default:
  54. return;
  55. }
  56.  
  57. e.preventDefault();
  58. });
  59. }
  60.  
  61. insertKeyBinds();