Sleazy Fork is available in English.

asmhentai next page

enhance asmhentai with auto loading

  1. // ==UserScript==
  2. // @name asmhentai next page
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2.0
  5. // @description enhance asmhentai with auto loading
  6. // @author Lin
  7. // @match https://asmhentai.com/gallery/*
  8. // @grant none
  9. // @require https://cdn.staticfile.org/blissfuljs/1.0.6/bliss.min.js
  10. // ==/UserScript==
  11.  
  12.  
  13. (function ($) {
  14. 'use strict';
  15. let body = document.body
  16. let button = document.createElement('button')
  17. button.textContent = 'next'
  18. button.style.position = 'fixed'
  19. button.style.right = '10px'
  20. button.style.top = '40%'
  21. button.style.width = '80px'
  22. button.style.height = '60px'
  23. body.appendChild(button)
  24. let url = location.href
  25. let num = +url.match(/(\d+?)\/$/)[1] // current page
  26. button.addEventListener('click', function () {
  27. location.href = url.replace(/(\d+?)\/$/, ++num)
  28. })
  29. let currentImg = $('#fimg').dataset.src || $('#fimg').src
  30. let container = $('#content .mid_rd')
  31. // flex-direction
  32. container.style.flexDirection = 'column'
  33. let imgUrl = getImgUrl(currentImg)
  34. let maxPage = getMaxPage()
  35. function loadImage(page) {
  36. let el = $.create('img', {
  37. className: 'lazy no_image',
  38. src: imgUrl(page),
  39. title: `page ${page}`,
  40. events: {
  41. onload() {
  42. console(page + 'loaded')
  43. }
  44. }
  45. })
  46. container.appendChild(el)
  47. }
  48. for (let i = 1; i <= 5; i++) {
  49. loadImage(++num)
  50. }
  51. let documentElement = document.documentElement
  52. let scrollDebounce = debounce(function() {
  53. if (documentElement.scrollTop + documentElement.clientHeight + 2000 > documentElement.scrollHeight) {
  54. for (let i = 1; i <= 5; i++) { // todo
  55. loadImage(++num)
  56. if (num >= maxPage) {
  57. return document._.unbind({
  58. scroll: scrollDebounce
  59. })
  60. }
  61. }
  62. }
  63. }, 600)
  64. document._.bind({
  65. scroll: scrollDebounce
  66. })
  67. })(Bliss);
  68.  
  69.  
  70. function getImgUrl(url) {
  71. let arr = url.split(/\d+?\./)
  72. return function (page) {
  73. return arr[0] + page + '.' + arr[1]
  74. }
  75. }
  76. function getMaxPage() {
  77. let option = $('.btm_rd .tp')
  78. return option.textContent
  79. }
  80.  
  81. function debounce(fn, wait) {
  82. let timer = null;
  83. return function () {
  84. let context = this
  85. let args = arguments
  86. if (timer) {
  87. clearTimeout(timer);
  88. timer = null;
  89. }
  90. timer = setTimeout(function () {
  91. fn.apply(context, args)
  92. }, wait)
  93. }
  94. }