Sleazy Fork is available in English.

e-hentai Scroll Mode

Scroll to browsing e-hentai's art.

  1. // ==UserScript==
  2. // @name e-hentai Scroll Mode
  3. // @name:zh-TW e-hentai 滾動模式
  4. // @name:zh-CN e-hentai 滚动模式
  5. // @name:ja e-hentai スクロールモード
  6. // @namespace https://greasyfork.org/zh-TW/users/142344-jasn-hr
  7. // @description Scroll to browsing e-hentai's art.
  8. // @description:zh-TW 在 e-hentai 滾動卷軸持續瀏覽
  9. // @description:zh-CN 在 e-hentai 滚动卷轴持续浏览
  10. // @description:ja e-hentaiスクロールスクロールでブラウジングを続ける
  11. // @copyright 2019, HrJasn (https://greasyfork.org/zh-TW/users/142344-jasn-hr)
  12. // @license GPL-3.0-or-later
  13. // @version 3.0.4
  14. // @icon https://www.google.com/s2/favicons?domain=e-hentai.org
  15. // @match http*://e-hentai.org/s/*
  16. // @match http*://exhentai.org/s/*
  17. // @exclude http*://www.e-hentai.org/*
  18. // @grant none
  19. // ==/UserScript==
  20.  
  21. (() => {
  22. const scrollMode_DIV = document.body.appendChild(document.createElement("div"));
  23. scrollMode_DIV.style = "z-index:999;position:fixed;cursor:pointer;left:0px;width:100%;height:0px;top:" + window.innerHeight + "px;-webkit-overflow-scrolling:touch;overflow-y:scroll;background-color:gray;transition:all 0.5s ease 0.5s;";
  24. let ImgJsonArr = [];
  25.  
  26. let mainImage = document.querySelector('#img').parentNode;
  27. let PrevBtn = document.querySelector('a[href *= "/s/"] > img[src *= "/p.png"]').parentNode;
  28. let NextBtn = document.querySelector('a[href *= "/s/"] > img[src *= "/n.png"]').parentNode;
  29. mainImage.querySelector('img').setAttribute("pageurl",window.location.href);
  30. ImgJsonArr.push({
  31. 'pageurl' : window.location.href,
  32. 'mainImage' : mainImage,
  33. 'PrevBtn' : PrevBtn,
  34. 'NextBtn' : NextBtn
  35. });
  36. function LoadBeforeImageToJsonArr(cnImg){
  37. fetch(cnImg.href).then(async (res)=>{
  38. return [res.url, await res.text()];
  39. }).then((res)=>{
  40. const parser = new DOMParser();
  41. const htmlDocument = parser.parseFromString(res[1], "text/html");
  42. const mImg = htmlDocument.documentElement.querySelector('#img').parentNode;
  43. const pImg = htmlDocument.documentElement.querySelector('a[href *= "/s/"] > img[src *= "/p.png"]').parentNode;
  44. const nImg = htmlDocument.documentElement.querySelector('a[href *= "/s/"] > img[src *= "/n.png"]').parentNode;
  45. mImg.querySelector('img').setAttribute("pageurl",res[0]);
  46. ImgJsonArr.unshift({
  47. 'pageurl' : res[0],
  48. 'mainImage' : mImg,
  49. 'PrevBtn' : pImg,
  50. 'NextBtn' : nImg
  51. });
  52. //console.log('Update ImgJsonArr: ', ImgJsonArr);
  53. if(pImg.href != cnImg.href){
  54. LoadBeforeImageToJsonArr(pImg);
  55. };
  56. });
  57. };
  58. LoadBeforeImageToJsonArr(PrevBtn);
  59. function LoadAfterImageToJsonArr(cnImg){
  60. fetch(cnImg.href).then(async (res)=>{
  61. return [res.url, await res.text()];
  62. }).then((res)=>{
  63. const parser = new DOMParser();
  64. const htmlDocument = parser.parseFromString(res[1], "text/html");
  65. const mImg = htmlDocument.documentElement.querySelector('#img').parentNode;
  66. const pImg = htmlDocument.documentElement.querySelector('a[href *= "/s/"] > img[src *= "/p.png"]').parentNode;
  67. const nImg = htmlDocument.documentElement.querySelector('a[href *= "/s/"] > img[src *= "/n.png"]').parentNode;
  68. mImg.querySelector('img').setAttribute("pageurl",res[0]);
  69. ImgJsonArr.push({
  70. 'pageurl' : res[0],
  71. 'mainImage' : mImg,
  72. 'PrevBtn' : pImg,
  73. 'NextBtn' : nImg
  74. });
  75. //console.log('Update ImgJsonArr: ', ImgJsonArr);
  76. if(nImg.href != cnImg.href){
  77. LoadAfterImageToJsonArr(nImg);
  78. };
  79. });
  80. };
  81. LoadAfterImageToJsonArr(NextBtn);
  82. function reSizeElmtFlwWidthIfScl(Elmt,scale = 0.75){
  83. Elmt.style.maxWidth = "";
  84. Elmt.style.maxHeight = "";
  85. let Elmt_originalWidth = Elmt.offsetWidth;
  86. let Elmt_originalHeight = Elmt.offsetHeight;
  87. Elmt.setAttribute("originalWidth",Elmt_originalWidth);
  88. Elmt.setAttribute("originalHeight",Elmt_originalHeight);
  89. Elmt.style.width = "100%";
  90. Elmt.style.height = (Elmt_originalHeight*Elmt.offsetWidth)/Elmt_originalWidth + "px";
  91. if( (Elmt.offsetWidth*scale > Elmt_originalWidth) || (Elmt.offsetheight*scale > Elmt_originalHeight) ){
  92. Elmt.style.width = Elmt_originalWidth + "px";
  93. Elmt.style.height = Elmt_originalHeight + "px";
  94. };
  95. return Elmt;
  96. };
  97. let lastScrollTop = 0;
  98. const UpdatescrollMode_DIV = (evnt) => {
  99. document.body.style.overflow = "hidden";
  100. let cuImg = null;
  101. let sMImgNl = scrollMode_DIV.querySelectorAll('img');
  102. let sMImgArr = [...sMImgNl];
  103. if(scrollMode_DIV.querySelector('img')){
  104. cuImg = sMImgArr.find((img)=>{
  105. return ( (document.body.offsetHeight > (img.y + img.offsetHeight)) && ((img.y + img.offsetHeight) > 0) )
  106. });
  107. } else {
  108. cuImg = ImgJsonArr.find((img)=>{
  109. return ( img.pageurl.match(/\-([^\-]+)$/)[1] == location.href.match(/\-([^\-]+)$/)[1] )
  110. });
  111. let mainImage_clone = cuImg.mainImage.querySelector('img').cloneNode(true);
  112. scrollMode_DIV.appendChild(mainImage_clone);
  113. mainImage_clone = reSizeElmtFlwWidthIfScl(mainImage_clone);
  114. cuImg = mainImage_clone;
  115. };
  116. if(cuImg){
  117. const currentScrollTop = (cuImg.y + cuImg.offsetHeight) || scrollMode_DIV.scrollTop;
  118. const IJAcuImg = ImgJsonArr.find((ij)=>{
  119. return ( ij.pageurl.match(/\-([^\-]+)$/)[1] == cuImg.getAttribute("pageurl").match(/\-([^\-]+)$/)[1] );
  120. });
  121. if (currentScrollTop > (lastScrollTop + (cuImg.offsetHeight*0.5))) {
  122. [...ImgJsonArr].forEach((ImgJson,ImgJsonIdx)=>{
  123. const IJACIdx = ImgJsonArr.indexOf(IJAcuImg);
  124. sMImgNl = scrollMode_DIV.querySelectorAll('img');
  125. sMImgArr = [...sMImgNl];
  126. if( ((IJACIdx-5) <= ImgJsonIdx) && (ImgJsonIdx < (IJACIdx+5)) ){
  127. let sMcuImg = null;
  128. sMcuImg = sMImgArr.find((sMImgNE)=>{
  129. return ( sMImgNE.getAttribute("pageurl").match(/\-([^\-]+)$/)[1] == ImgJson.pageurl.match(/\-([^\-]+)$/)[1] );
  130. });
  131. if( !(sMcuImg) ){
  132. let mainImage_clone = ImgJson.mainImage.querySelector('img').cloneNode(true);
  133. scrollMode_DIV.appendChild(mainImage_clone);
  134. mainImage_clone = reSizeElmtFlwWidthIfScl(mainImage_clone);
  135. sMcuImg = mainImage_clone;
  136. };
  137. if ( !(evnt) && (sMcuImg) && (sMcuImg.getAttribute("pageurl").match(/\-([^\-]+)$/)[1] == location.href.match(/\-([^\-]+)$/)[1]) ) {
  138. sMcuImg.scrollIntoView();
  139. };
  140. };
  141. if( ImgJsonIdx < (IJACIdx-5) ){
  142. sMImgNl.forEach((sMImgNE)=>{
  143. if( ImgJson.pageurl.match(/\-([^\-]+)$/)[1] == sMImgNE.getAttribute("pageurl").match(/\-([^\-]+)$/)[1] ){
  144. sMImgNE.remove();
  145. };
  146. });
  147. };
  148. });
  149. lastScrollTop = currentScrollTop;
  150. } else if (currentScrollTop < (lastScrollTop - (cuImg.offsetHeight*0.5))) {
  151. const ImgJsonArrRvsd = [...ImgJsonArr].reverse();
  152. [...ImgJsonArrRvsd].forEach((ImgJson,ImgJsonIdx)=>{
  153. const IJACIdx = ImgJsonArrRvsd.indexOf(IJAcuImg);
  154. sMImgNl = scrollMode_DIV.querySelectorAll('img');
  155. sMImgArr = [...sMImgNl];
  156. if( ((IJACIdx+5) >= ImgJsonIdx) && (ImgJsonIdx > (IJACIdx-5)) ){
  157. let sMcuImg = null;
  158. sMcuImg = sMImgArr.find((sMImgNE)=>{
  159. return ( sMImgNE.getAttribute("pageurl").match(/\-([^\-]+)$/)[1] == ImgJson.pageurl.match(/\-([^\-]+)$/)[1] );
  160. });
  161. if( !(sMcuImg) ){
  162. let mainImage_clone = ImgJson.mainImage.querySelector('img').cloneNode(true);
  163. scrollMode_DIV.insertBefore(mainImage_clone,sMImgArr[0]);
  164. mainImage_clone = reSizeElmtFlwWidthIfScl(mainImage_clone);
  165. sMcuImg = mainImage_clone;
  166. };
  167. if ( !(evnt) && (sMcuImg) && (sMcuImg.getAttribute("pageurl").match(/\-([^\-]+)$/)[1] == location.href.match(/\-([^\-]+)$/)[1]) ) {
  168. sMcuImg.scrollIntoView();
  169. };
  170. };
  171. if( ImgJsonIdx <= (IJACIdx-5) ){
  172. sMImgNl.forEach((sMImgNE)=>{
  173. if( ImgJson.pageurl.match(/\-([^\-]+)$/)[1] == sMImgNE.getAttribute("pageurl").match(/\-([^\-]+)$/)[1] ){
  174. sMImgNE.remove();
  175. };
  176. });
  177. };
  178. });
  179. lastScrollTop = currentScrollTop;
  180. };
  181. };
  182. };
  183. const ShowscrollMode_DIV = () => {
  184. let cuImg = null;
  185. let currentScrollTop = window.pageYOffset || document.documentElement.scrollTop;
  186. if ( (currentScrollTop >= lastScrollTop) && (currentScrollTop + window.innerHeight >= document.body.offsetHeight*0.99) ) {
  187. document.body.style.overflow="hidden";
  188. scrollMode_DIV.style.height = "100%";
  189. scrollMode_DIV.style.top = '0px';
  190. scrollMode_DIV.addEventListener("wheel",UpdatescrollMode_DIV,false);
  191. scrollMode_DIV.addEventListener("scroll",UpdatescrollMode_DIV,false);
  192. scrollMode_DIV.addEventListener("keydown",UpdatescrollMode_DIV,false);
  193. document.removeEventListener("wheel",ShowscrollMode_DIV,false);
  194. document.removeEventListener("scroll",ShowscrollMode_DIV,false);
  195. document.removeEventListener("keydown",ShowscrollMode_DIV,false);
  196. scrollMode_DIV.focus();
  197. UpdatescrollMode_DIV();
  198. };
  199. lastScrollTop = currentScrollTop;
  200. };
  201. document.addEventListener("wheel",ShowscrollMode_DIV,false);
  202. document.addEventListener("scroll",ShowscrollMode_DIV,false);
  203. document.addEventListener("keydown",ShowscrollMode_DIV,false);
  204. const HidescrollMode_DIV = () => {
  205. scrollMode_DIV.style.height = '0px';
  206. scrollMode_DIV.style.top = window.innerHeight + 'px';
  207. document.body.style.overflow = "scroll";
  208. scrollMode_DIV.removeEventListener("wheel",UpdatescrollMode_DIV,false);
  209. scrollMode_DIV.removeEventListener("scroll",UpdatescrollMode_DIV,false);
  210. scrollMode_DIV.removeEventListener("keydown",UpdatescrollMode_DIV,false);
  211. document.body.focus();
  212. document.body.scrollTo({
  213. top: document.body.offsetHeight*0.8,
  214. behavior: "smooth"
  215. });
  216. document.addEventListener("wheel",ShowscrollMode_DIV,false);
  217. document.addEventListener("scroll",ShowscrollMode_DIV,false);
  218. document.addEventListener("keydown",ShowscrollMode_DIV,false);
  219. const sMImgNl = scrollMode_DIV.querySelectorAll('img');
  220. const cuImg = [...sMImgNl].find((img)=>{
  221. return ( (document.body.offsetHeight > (img.y + img.offsetHeight)) && ((img.y + img.offsetHeight) > 0) )
  222. });
  223. window.location.href = cuImg.getAttribute("pageurl");
  224. };
  225. scrollMode_DIV.addEventListener("click",HidescrollMode_DIV,false);
  226. window.addEventListener('resize', ()=>{
  227. scrollMode_DIV.querySelectorAll('img').forEach((img)=>{
  228. reSizeElmtFlwWidthIfScl(img);
  229. });
  230. });
  231. })();