Nhentai scroll

scroll to read picture in nhentai

  1. // ==UserScript==
  2. // @name Nhentai scroll
  3. // @namespace https://github.com/Yan-Bin-Lin/nhentai_scroll_slide
  4. // @version 0.5
  5. // @description scroll to read picture in nhentai
  6. // @author Lin Yan Bin
  7. // @match https://nhentai.net/g/*/*/
  8. // @require https://code.jquery.com/jquery-3.5.1.min.js
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12. (function() {
  13. let target = '#image-container';
  14. let ic = $("#image-container");
  15. let num = parseInt($("span.num-pages").first().text());
  16. let img = ic.find("img");
  17. let src = img.attr("src");
  18. let base = src.slice(0, src.lastIndexOf("/") + 1);
  19. let width = img.attr("width");
  20. let height = img.attr("height");
  21. let start = parseInt(window.location.pathname.slice(0, -1).split('/').pop()) + 1
  22.  
  23. function insertImage(event) {
  24. let base = event.data.base
  25. let i = event.data.i
  26. let url = base + (i - 1).toString()
  27. if ($(target).find('img[src$="' + url + '.jpg"]').length > 0) {
  28. $('img[src$="' + url + '.jpg"]').after($(this));
  29. } else if ($(target).find('img[src$="' + url + '.png"]').length > 0) {
  30. $('img[src$="' + url + '.png"]').after($(this));
  31. } else {
  32. $(this).appendTo(target);
  33. }
  34. }
  35.  
  36.  
  37. function loadImage(base, i, width, height) {
  38. let url = base + i.toString();
  39. $('<img src="'+ url + '.jpg' +'">')
  40. .one("load", {base: base, i: i}, insertImage)
  41. .one("error", function() {
  42. $('<img src="'+ url + '.png' +'">')
  43. .one("load", {base: base, i: i}, insertImage)
  44. });
  45. }
  46.  
  47. for (let i = start;i <= num; i++){
  48. window.setTimeout(function() {
  49. loadImage(base, i, width, height);
  50. }, 750 * (i - start));
  51.  
  52. }
  53.  
  54. })();