Sleazy Fork is available in English.

Powerfap

Adds full screen lightbox feature (with preloading) for imagefap galleries. Just click on image thumbnail from the category or homepage.

  1. // ==UserScript==
  2. // @name Powerfap
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0.1
  5. // @description Adds full screen lightbox feature (with preloading) for imagefap galleries. Just click on image thumbnail from the category or homepage.
  6. // @author Alekc
  7. // @license MIT
  8. // @copyright 2019, alekc (https://openuserjs.org/users/alekc)
  9. // @match https://www.imagefap.com/*
  10. // @require https://cdn.jsdelivr.net/npm/lightgallery.js@1.1.3/dist/js/lightgallery.js
  11. // @require https://cdn.jsdelivr.net/npm/lg-thumbnail.js@1.1.0/dist/lg-thumbnail.min.js
  12. // @require https://cdn.jsdelivr.net/npm/lg-zoom.js@1.0.1/dist/lg-zoom.min.js
  13. // @require https://cdn.jsdelivr.net/npm/lg-autoplay.js@1.0.0/dist/lg-autoplay.min.js
  14. // @grant none
  15. // ==/UserScript==
  16.  
  17. const head_inject = `
  18. <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/sachinchoolur/lightgallery.js@master/dist/css/lightgallery.css">
  19. <style>
  20. #overlay {
  21. position: fixed;
  22. top: 0;
  23. right: 0;
  24. bottom: 0;
  25. left: 0;
  26. overflow: hidden;
  27. z-index: 2000;
  28. background-color: #000;
  29. opacity: 0.7;
  30. -webkit-animation: slbOverlay 0.5s;
  31. -moz-animation: slbOverlay 0.5s;
  32. animation: slbOverlay 0.5s;
  33. }
  34. .lds-ellipsis {
  35. display: inline-block;
  36. position: relative;
  37. width: 64px;
  38. height: 64px;
  39. }
  40. .lds-ellipsis div {
  41. position: absolute;
  42. top: 27px;
  43. width: 11px;
  44. height: 11px;
  45. border-radius: 50%;
  46. background: #fff;
  47. animation-timing-function: cubic-bezier(0, 1, 1, 0);
  48. }
  49. .lds-ellipsis div:nth-child(1) {
  50. left: 6px;
  51. animation: lds-ellipsis1 0.6s infinite;
  52. }
  53. .lds-ellipsis div:nth-child(2) {
  54. left: 6px;
  55. animation: lds-ellipsis2 0.6s infinite;
  56. }
  57. .lds-ellipsis div:nth-child(3) {
  58. left: 26px;
  59. animation: lds-ellipsis2 0.6s infinite;
  60. }
  61. .lds-ellipsis div:nth-child(4) {
  62. left: 45px;
  63. animation: lds-ellipsis3 0.6s infinite;
  64. }
  65. @keyframes lds-ellipsis1 {
  66. 0% {
  67. transform: scale(0);
  68. }
  69. 100% {
  70. transform: scale(1);
  71. }
  72. }
  73. @keyframes lds-ellipsis3 {
  74. 0% {
  75. transform: scale(1);
  76. }
  77. 100% {
  78. transform: scale(0);
  79. }
  80. }
  81. @keyframes lds-ellipsis2 {
  82. 0% {
  83. transform: translate(0, 0);
  84. }
  85. 100% {
  86. transform: translate(19px, 0);
  87. }
  88. }
  89. #overlay {
  90.  
  91. display:none;
  92. }
  93. #overlay .lds-ellipsis {
  94. position: absolute;
  95. top: 50%;
  96. left: 50%;
  97. transform: translate(-50%, -50%);
  98. }
  99. </style>
  100. `;
  101.  
  102. const body_inject = `
  103. <div id="fap-gal" style=""></div>
  104. <div id='overlay'><div class="lds-ellipsis"><div></div><div></div><div></div><div></div></div></div>
  105. `;
  106.  
  107. var $ = window.$;
  108. const galRegex = /\/photo\/(\d+)/m;
  109. const homeRegex = /image\.php\?id=(\d+)/m;
  110.  
  111. var preloadedImages = [];
  112. var resultCache = [];
  113. var lightBox;
  114. (function () {
  115. 'use strict';
  116.  
  117. //prepare requirements
  118. $("head").append(head_inject);
  119. $("body").append(body_inject);
  120.  
  121. //link from category page
  122. $("img.gal_thumb").parent("a").click(function () {
  123. event.preventDefault();
  124. showOverlay();
  125. var match = galRegex.exec($(this).attr("href"));
  126. if (match === null) {
  127. alert("can't find photo id");
  128. return;
  129. }
  130.  
  131. var galId = $(this).closest("tr[valign='top']").prev().attr("id");
  132. var photoId = match[1];
  133. preRun(photoId, galId);
  134. });
  135.  
  136. $('a[href*="image.php?id="]').click(function () {
  137. event.preventDefault();
  138. showOverlay();
  139. var match = homeRegex.exec($(this).attr("href"));
  140. if (match === null) {
  141. alert("can't find photo id");
  142. return;
  143. }
  144.  
  145. var galId = $(this).closest("tr:not([bgcolor])").prev().attr("id");
  146. var photoId = match[1];
  147. preRun(photoId, galId);
  148. });
  149. //
  150. })();
  151.  
  152. function showOverlay() {
  153. $("#overlay").show();
  154. }
  155.  
  156. function hideOverlay() {
  157. $("#overlay").hide();
  158. }
  159.  
  160. function preRun(photoId, galId) {
  161. var key = calculateCacheKey(photoId, galId);
  162. if (typeof (resultCache[key]) !== "undefined") {
  163. showGallery(resultCache[key]);
  164. return;
  165. }
  166. run(photoId, galId, []);
  167. }
  168.  
  169. function calculateCacheKey(photoId, galId) {
  170. return galId;
  171. }
  172.  
  173. function run(photoId, galId, result) {
  174. var url = "https://www.imagefap.com/photo/" + photoId + "/?gid=" + galId + "&idx=" + result.length + "&partial=true";
  175. console.log(url);
  176. $.ajax({
  177. url: url,
  178. type: "GET",
  179. dataType: "html",
  180. success: function (data) {
  181. var newLinks = [];
  182. $(data).find("a").each(function () {
  183. var href = $(this).attr("href");
  184. var thumb = $(this).find("img").attr("src");
  185. newLinks.push({
  186. src: href,
  187. thumb: thumb
  188. });
  189. });
  190. result = result.concat(newLinks);
  191. if (newLinks.length === 0 || newLinks.length < 24) {
  192. resultCache[calculateCacheKey(photoId, galId)] = result;
  193. showGallery(result);
  194. return;
  195. }
  196. run(photoId, galId, result);
  197. },
  198. error: function (jqXHR, textStatus, errorThrown) {
  199. alert("Error: " + textStatus + " (" + errorThrown + ")");
  200. hideOverlay();
  201. }
  202. });
  203. }
  204.  
  205. function preloadImage(href) {
  206. if (href === 'undefined' || typeof (preloadedImages[href]) !== 'undefined') {
  207. return;
  208. }
  209. preloadedImages[href] = new Image();
  210. preloadedImages[href].src = href;
  211. }
  212.  
  213. function showGallery(items) {
  214. hideOverlay();
  215. var el = document.getElementById("fap-gal");
  216. //destroy on closure
  217. el.addEventListener('onCloseAfter', function (e) {
  218. window.lgData[$(this).attr('lg-uid')].destroy(true);
  219. }, false);
  220.  
  221. //slide change
  222. /*
  223. el.addEventListener('onAfterSlide', function(event){
  224. items = window.lgData[$(this).attr('lg-uid')].items;
  225. for (var i = event.detail.index + 1; i<items.length && i < event.detail.index + 6; i++){
  226. preloadImage(items[i].src);
  227. }
  228. //event.detail.index
  229. }, false);
  230. */
  231.  
  232. lightGallery(el, {
  233. dynamic: true,
  234. dynamicEl: items,
  235. preload: 3,
  236. });
  237. }
  238.  
  239. function injectJs(link) {
  240. var scr = document.createElement('script');
  241. scr.type = "text/javascript";
  242. scr.src = link;
  243. document.getElementsByTagName('head')[0].appendChild(scr)
  244. }