Guest User

ImageFap Gallery Link Indexer

a guest
Jul 19th, 2026
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. // ==UserScript==
  2. // @name ImageFap Gallery Link Indexer + Continuous Pagination
  3. // @namespace http://tampermonkey.net
  4. // @version 3.0
  5. // @description Calculates the page offset to maintain strict #0, #1, #2 sequential numbering across different gallery pages
  6. // @author Gemini
  7. // @match https://www.imagefap.com/pictures/*
  8. // @match https://www.imagefap.com/gallery/*
  9. // @run-at document-end
  10. // @grant none
  11. // @license free, as is
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. let isUpdating = false;
  18.  
  19. // Helper function to extract URL parameters
  20. function getUrlParameter(name, url = window.location.href) {
  21. name = name.replace(/[\[\]]/g, '\\$&');
  22. const regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)');
  23. const results = regex.exec(url);
  24. if (!results) return null;
  25. if (!results[2]) return '';
  26. return decodeURIComponent(results[2].replace(/\+/g, ' '));
  27. }
  28.  
  29. // Determine the base starting index based on the view mode and current page number
  30. function calculateStartingIndex() {
  31. const viewMode = getUrlParameter('view') || '2'; // Default to One Page (view=2) if not specified
  32. const pageParam = getUrlParameter('page') || '0'; // Default to first page (page=0)
  33.  
  34. const pageNumber = parseInt(pageParam, 10) || 0;
  35. let itemsPerPage = 100; // Grid size for One Page mode (4x25 = 100)
  36.  
  37. if (viewMode === '0') {
  38. itemsPerPage = 24; // Grid size for Detailed View mode (4x6 = 24)
  39. }
  40.  
  41. // Formula: page_number * items_per_page
  42. return pageNumber * itemsPerPage;
  43. }
  44.  
  45. function processGalleryLinks() {
  46. if (isUpdating) return;
  47.  
  48. const gallery = document.getElementById('gallery');
  49. if (!gallery) {
  50. console.log("[Tampermonkey] #gallery container not found on this page.");
  51. return;
  52. }
  53.  
  54. isUpdating = true;
  55.  
  56. // Calculate where the count should start for this specific page
  57. const startingOffset = calculateStartingIndex();
  58.  
  59. const links = gallery.querySelectorAll('a');
  60. let localIndex = 0;
  61.  
  62. links.forEach((link) => {
  63. const rawHref = link.getAttribute('href');
  64.  
  65. if (rawHref && rawHref.includes('/photo/')) {
  66. // Total global index = starting page offset + relative link order on current page
  67. const globalIndex = startingOffset + localIndex;
  68. const targetHash = '#' + globalIndex;
  69.  
  70. if (!rawHref.endsWith(targetHash)) {
  71. const baseUrl = rawHref.split('#'); // Clear any existing trailing hash
  72. link.setAttribute('href', baseUrl + targetHash);
  73. }
  74.  
  75. localIndex++;
  76. }
  77. });
  78.  
  79. console.log(`[Tampermonkey] Page Offset: ${startingOffset}. Successfully indexed links on this page: ${localIndex}`);
  80. isUpdating = false;
  81. }
  82.  
  83. // Initialize layout processing immediately
  84. processGalleryLinks();
  85.  
  86. // Watch for infinite scroll additions or live DOM manipulations
  87. const observer = new MutationObserver((mutations) => {
  88. for (let mutation of mutations) {
  89. if (mutation.addedNodes.length > 0) {
  90. processGalleryLinks();
  91. break;
  92. }
  93. }
  94. });
  95.  
  96. const targetNode = document.getElementById('gallery');
  97. if (targetNode) {
  98. observer.observe(targetNode, { childList: true, subtree: true });
  99. }
  100.  
  101. // Fallback trigger in case layout structure renders after minor delays
  102. window.addEventListener('load', () => {
  103. setTimeout(processGalleryLinks, 300);
  104. });
  105.  
  106. })();
  107.  
Tags: imagefap
Advertisement
Add Comment
Please, Sign In to add comment