GraphicEx More Pages

Allows users to control the number of pages shown in pagination on graphicex.com

  1. // ==UserScript==
  2. // @name GraphicEx More Pages
  3. // @namespace https://greasyfork.org/en/users/781396-yad
  4. // @version 1.8
  5. // @description Allows users to control the number of pages shown in pagination on graphicex.com
  6. // @author YAD
  7. // @icon https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSxsA3xubmAnVbFJqEgajTJW0kIy7UzO9UEcA&s
  8. // @match https://graphicex.com/*
  9. // @license NO-REDISTRIBUTION
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. const PAGINATION_KEY = 'graphicexCurrentPage';
  17. let currentPage = parseInt(localStorage.getItem(PAGINATION_KEY)) || 1;
  18.  
  19. // Function to update pagination
  20. function updatePagination(totalPages) {
  21. const navigationDiv = document.querySelector('.navigation.ignore-select');
  22. if (!navigationDiv) return;
  23.  
  24. // Clear existing page links (keep the first span element which indicates the current page)
  25. const existingLinks = Array.from(navigationDiv.children).filter(child => child.tagName === 'A' || (child.tagName === 'SPAN' && child !== navigationDiv.firstElementChild));
  26. existingLinks.forEach(link => link.remove());
  27.  
  28. // Add new page links
  29. for (let i = 1; i <= totalPages; i++) {
  30. if (i === currentPage) {
  31. const currentPageSpan = document.createElement('span');
  32. currentPageSpan.textContent = i;
  33. currentPageSpan.classList.add('active');
  34. navigationDiv.insertBefore(currentPageSpan, navigationDiv.querySelector('#nextlink'));
  35. } else {
  36. const pageLink = document.createElement('a');
  37. pageLink.href = "#";
  38. pageLink.textContent = i;
  39. pageLink.onclick = (function(page) {
  40. return function() {
  41. currentPage = page; // Update current page
  42. localStorage.setItem(PAGINATION_KEY, currentPage); // Save current page to localStorage
  43. list_submit(page);
  44. return false;
  45. };
  46. })(i);
  47. navigationDiv.insertBefore(pageLink, navigationDiv.querySelector('#nextlink'));
  48. }
  49. }
  50. }
  51.  
  52. // Function to add input for the number of pages
  53. function addPageInput() {
  54. const navigationDiv = document.querySelector('.navigation.ignore-select');
  55. if (!navigationDiv) return;
  56.  
  57. const savedTotalPages = localStorage.getItem('graphicexTotalPages') || 10;
  58.  
  59. const label = document.createElement('label');
  60. label.textContent = 'Show pages:';
  61. label.style.marginLeft = '10px';
  62.  
  63. const input = document.createElement('input');
  64. input.type = 'number';
  65. input.min = 1;
  66. input.style.width = '50px';
  67. input.style.marginLeft = '5px';
  68. input.value = savedTotalPages; // Load saved value
  69.  
  70. input.addEventListener('change', function() {
  71. const totalPages = parseInt(input.value);
  72. if (totalPages >= 1) {
  73. localStorage.setItem('graphicexTotalPages', totalPages); // Save the value
  74. updatePagination(totalPages);
  75. }
  76. });
  77.  
  78. navigationDiv.appendChild(label);
  79. navigationDiv.appendChild(input);
  80.  
  81. updatePagination(savedTotalPages); // Initialize with saved or default pages
  82. }
  83.  
  84. // Wait for the page to load and then add the input field and update pagination
  85. window.addEventListener('load', function() {
  86. addPageInput();
  87. });
  88. })();