nhentai-infinite-scroll

nhentai infinite scroll.

  1. // ==UserScript==
  2. // @name nhentai-infinite-scroll
  3. // @namespace Violentmonkey Scripts
  4. // @version 1.0.0
  5. // @description nhentai infinite scroll.
  6. // @author anonymous
  7. // @match https://nhentai.net/g/*/
  8. // @grant none
  9. // @license MIT
  10. // @icon https://i.imgur.com/I5Muasr.png
  11. // ==/UserScript==
  12. (function () {
  13. "use strict";
  14.  
  15. let thumbnailContainer = document.getElementById("thumbnail-container");
  16. let gallerythumb = document.getElementsByClassName("gallerythumb");
  17.  
  18. if (
  19. thumbnailContainer === null ||
  20. gallerythumb === null ||
  21. gallerythumb.length === 0
  22. )
  23. return;
  24.  
  25. let formats = [];
  26.  
  27. let sheet = (function () {
  28. let style = document.createElement("style");
  29. style.appendChild(document.createTextNode(""));
  30. document.head.appendChild(style);
  31. return style.sheet;
  32. })();
  33.  
  34. sheet.insertRule("#thumbnail-container > img { width: 100%; }", 0);
  35.  
  36. let mid = document
  37. .getElementById("cover")
  38. .getElementsByTagName("img")[0]
  39. .src.split("/")[4];
  40.  
  41. for (let a of gallerythumb) {
  42. let s = a.firstElementChild.getAttribute("data-src").split("/");
  43. formats.push(s[5].split(".")[1]);
  44. mid = s[4];
  45. }
  46.  
  47. while (thumbnailContainer.firstChild) {
  48. thumbnailContainer.removeChild(thumbnailContainer.firstChild);
  49. }
  50.  
  51. let lastId = 0;
  52. let timerId = null;
  53. loadNextImage();
  54.  
  55. function loadNextImage() {
  56. if (timerId !== null) {
  57. clearTimeout(timerId);
  58. timerId = null;
  59. }
  60.  
  61. let image = new Image();
  62. image.src =
  63. "https://i.nhentai.net/galleries/" +
  64. mid +
  65. "/" +
  66. (lastId + 1) +
  67. "." +
  68. formats[lastId];
  69. thumbnailContainer.append(image);
  70.  
  71. image.onload = function () {
  72. lastId++;
  73. if (lastId < formats.length) {
  74. loadNextImage();
  75. }
  76. };
  77.  
  78. image.onerror = function () {
  79. thumbnailContainer.lastElementChild.remove();
  80. timerId = setTimeout(loadNextImage, 1000);
  81. };
  82. }
  83. })();