ExHentai autoscroll and next

automatic scroll and next for easier, handless reading of exHentai galleries

  1. // ==UserScript==
  2. // @name ExHentai autoscroll and next
  3. // @namespace none
  4. // @version 0.1
  5. // @description automatic scroll and next for easier, handless reading of exHentai galleries
  6. // @author saddestpandaever
  7. // @match *://exhentai.org/s/*
  8. // ==/UserScript==
  9.  
  10. (function() {
  11. 'use strict';
  12. var header = document.getElementsByTagName("h1")[0];
  13. var button = document.createElement("button");
  14. button.innerHTML = "Start scrolling";
  15. button.onclick = function(){
  16. scrollDown(20);
  17. };
  18. header.appendChild(button);
  19. })();
  20.  
  21. function sleep(ms) {
  22. return new Promise(resolve => setTimeout(resolve, ms));
  23. }
  24.  
  25. async function clickNext(next){
  26. await sleep(2000);
  27. next.click();
  28. }
  29.  
  30. async function scrollDown(delay){
  31.  
  32. var windowScrollBottom, botDiv = document.getElementById("i4"), next = document.getElementById("next"), imagediv = document.getElementById("i3");
  33.  
  34. var plus = document.createElement("button"), minus=document.createElement("button"), pause = document.createElement("button"), paused=false, speedindicator = document.createElement("text");
  35. plus.innerHTML = "+"; minus.innerHTML = "-"; pause.innerHTML = "P"; speedindicator.innerHTML = Math.floor(1000/delay)+"px/s";
  36. plus.setAttribute("style", "width:30; height:30; margin-left: -30px; background-color: #666666; position:fixed");
  37. minus.setAttribute("style", "width:30; height:30; margin-left: -30px; background-color: #666666; margin-top: 20px; position:fixed");
  38. pause.setAttribute("style", "width:30; height:30; margin-left: -30px; background-color: #666666; margin-top: 40px; position:fixed");
  39. speedindicator.setAttribute("style", "width:30; height:30; margin-left: -30px; margin-top: 65px; position:fixed");
  40. function updateSpeedIndicator(){
  41. speedindicator.innerHTML = Math.floor(1000/delay) + "px/s";
  42. }
  43.  
  44. plus.onclick = function() {
  45. if(delay > 2) delay=delay-2;
  46. updateSpeedIndicator();
  47. };
  48. minus.onclick = function() {
  49. delay=delay+2;
  50. updateSpeedIndicator();
  51.  
  52. };
  53. pause.onclick = function() {
  54. paused=!paused;
  55. };
  56. imagediv.prepend(plus, minus, pause,speedindicator);
  57.  
  58.  
  59. while(true){
  60. while(paused){ await sleep(10);}
  61.  
  62. await sleep(delay);
  63. window.scrollBy(0, 1);
  64. windowScrollBottom=window.pageYOffset + window.innerHeight;
  65.  
  66. if(windowScrollBottom > botDiv.offsetTop){
  67. next = document.getElementById("next");
  68. await sleep(1500);//ms to stay at the bottom of the page before going to the next
  69. await clickNext(next);
  70. await sleep(300);
  71.  
  72. imagediv = document.getElementById("i3");
  73. await imagediv.scrollIntoView();
  74. imagediv.prepend(plus, minus, pause,speedindicator);
  75.  
  76. await sleep(1500);//ms before starting to scroll
  77. }
  78. }
  79. }