Sleazy Fork is available in English.

EX Better Thumbnails

Provides infinite scroll and larger thumbnails for gallery browsing.

  1. // ==UserScript==
  2. // @name EX Better Thumbnails
  3. // @description Provides infinite scroll and larger thumbnails for gallery browsing.
  4. // @version 0.63
  5. // @match https://exhentai.org/g/*
  6. // @grant none
  7. // @namespace https://greasyfork.org/users/13871
  8. // ==/UserScript==
  9.  
  10. const titleInputBoxMode = false;
  11.  
  12. var thisURL = document.createElement("a");
  13. thisURL.href = document.URL;
  14. var i = 0;
  15. var URLGen = URLGenerator();
  16. var fileCount;
  17. var len = 0;
  18. var gdata;
  19. const jQueryCDN = "https://code.jquery.com/jquery-1.11.3.min.js";
  20. const api = "https://exhentai.org/api.php";
  21.  
  22. const CSSCode = ".select {float: left}";
  23.  
  24. function loadJS(URL, callback) {
  25. var js = document.createElement("script");
  26. js.type = "text/javascript";
  27. js.src = URL;
  28. if (callback) {
  29. js.onload = callback;
  30. }
  31. document.head.appendChild(js);
  32. }
  33.  
  34. (function() {
  35. callback = function() {
  36. changeLayout();
  37. injectCSS();
  38. // injectBar();
  39. request(gid, token);
  40. main();
  41. }
  42. loadJS(jQueryCDN, callback);
  43. })();
  44.  
  45. function injectCSS() {
  46. var css = $("<style></style>");
  47. css.html(CSSCode);
  48. $("body").append(css);
  49. }
  50.  
  51. function injectBar() {
  52. $('<div id="controlbar"></div>').prependTo($("#gdt"));
  53. var button = $('<button id="debug">debug</button>').click(function() {listChecked();});
  54. $('#controlbar').append(button);
  55. }
  56.  
  57. function request(gid, token) {
  58. var data = {
  59. method: "gdata",
  60. gidlist: [
  61. [gid, token]
  62. ]
  63. };
  64. data = JSON.stringify(data);
  65. var r = $.ajax({
  66. url: api,
  67. data: data,
  68. dataType: "JSON",
  69. type: "POST",
  70. contentType: "application/json",
  71. success: function(res, error) {
  72. gdata = res;
  73. fileCount = Number(gdata["gmetadata"][0]["filecount"]);
  74. console.log("File count: " + fileCount);
  75. }
  76. });
  77. }
  78.  
  79. function* URLGenerator() {
  80. var base = thisURL.protocol + "//" + thisURL.hostname + thisURL.pathname + "?inline_set=ts_l";
  81. while (true) {
  82. yield base + "&" + "p=" + i;
  83. i += 1;
  84. }
  85. }
  86.  
  87. function openPageURL(URL, elem) {
  88. var callback = function(data) {
  89. var DOM = $.parseHTML(data);
  90. var imgURL = $(DOM).find("#img").prop("src");
  91. var original = ""
  92. try {
  93. original = $(DOM).find("#i7").find("a").prop("href");
  94. } catch (err) {
  95. console.log(err);
  96. }
  97. if (original) {
  98. imgURL = original;
  99. }
  100. if (elem) {
  101. var k = document.createElement('a');
  102. k.href = imgURL;
  103. k.download = true;
  104. k.click();
  105. k.remove();
  106. }
  107. }
  108. $.get(URL, callback);
  109. }
  110.  
  111. function insert(URL) {
  112. $.get(URL, function(data) {
  113. var DOM = $.parseHTML(data);
  114. $(DOM).find(".gdtl").each(function() {
  115. var title = $(this).find("img").prop("title");
  116. var fname = title
  117. var caption = $('<div class="caption"></div>');
  118. $(caption).appendTo(this);
  119. var pageURL = $(this).find("a").prop("href");
  120. $(caption).html("<a href=" + '"javascript: void(0);"' +">"+ fname + "</a>");
  121. $(caption).find("a").click(function() {
  122. openPageURL(pageURL, $(caption).find("a"));
  123. });
  124. $("#gdt > .c").before(this);
  125. $(this).hide().fadeIn();
  126. });
  127. })
  128. }
  129.  
  130. function call() {
  131. var url = URLGen.next().value;
  132. console.log(url);
  133. insert(url);
  134. }
  135.  
  136. function changeLayout() {
  137. if (titleInputBoxMode) {
  138. var i =$( '<input type="text" value=""></input>');
  139. i.prop("value", $("#gn").html());
  140. $("#gn").html(i);
  141. }
  142. $("#asm, #gdo, .gtb, #frontpage").remove();
  143. var thumbnails = document.getElementById("gdt");
  144. document.body.insertBefore(thumbnails, document.body.lastChild);
  145. $(".gdtm, .gdtl").each(function() {
  146. $(this).remove()
  147. })
  148. }
  149.  
  150. function main() {
  151. if (len == 0) {
  152. call();
  153. }
  154. $(window).scroll(function() {
  155. len = $(".gdtl").length;
  156. if (len < fileCount && window.innerHeight + window.scrollY >= document.body.offsetHeight) {
  157. call();
  158. }
  159. })
  160. }