GraphicEx More Pages

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

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

Bạn sẽ cần cài đặt một tiện ích mở rộng như Tampermonkey hoặc Violentmonkey để cài đặt kịch bản này.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         GraphicEx More Pages
// @namespace    https://greasyfork.org/en/users/781396-yad
// @version      1.8
// @description  Allows users to control the number of pages shown in pagination on graphicex.com
// @author       YAD
// @icon         https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSxsA3xubmAnVbFJqEgajTJW0kIy7UzO9UEcA&s
// @match        https://graphicex.com/*
// @license      NO-REDISTRIBUTION
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const PAGINATION_KEY = 'graphicexCurrentPage';
    let currentPage = parseInt(localStorage.getItem(PAGINATION_KEY)) || 1;

    // Function to update pagination
    function updatePagination(totalPages) {
        const navigationDiv = document.querySelector('.navigation.ignore-select');
        if (!navigationDiv) return;

        // Clear existing page links (keep the first span element which indicates the current page)
        const existingLinks = Array.from(navigationDiv.children).filter(child => child.tagName === 'A' || (child.tagName === 'SPAN' && child !== navigationDiv.firstElementChild));
        existingLinks.forEach(link => link.remove());

        // Add new page links
        for (let i = 1; i <= totalPages; i++) {
            if (i === currentPage) {
                const currentPageSpan = document.createElement('span');
                currentPageSpan.textContent = i;
                currentPageSpan.classList.add('active');
                navigationDiv.insertBefore(currentPageSpan, navigationDiv.querySelector('#nextlink'));
            } else {
                const pageLink = document.createElement('a');
                pageLink.href = "#";
                pageLink.textContent = i;
                pageLink.onclick = (function(page) {
                    return function() {
                        currentPage = page; // Update current page
                        localStorage.setItem(PAGINATION_KEY, currentPage); // Save current page to localStorage
                        list_submit(page);
                        return false;
                    };
                })(i);
                navigationDiv.insertBefore(pageLink, navigationDiv.querySelector('#nextlink'));
            }
        }
    }

    // Function to add input for the number of pages
    function addPageInput() {
        const navigationDiv = document.querySelector('.navigation.ignore-select');
        if (!navigationDiv) return;

        const savedTotalPages = localStorage.getItem('graphicexTotalPages') || 10;

        const label = document.createElement('label');
        label.textContent = 'Show pages:';
        label.style.marginLeft = '10px';

        const input = document.createElement('input');
        input.type = 'number';
        input.min = 1;
        input.style.width = '50px';
        input.style.marginLeft = '5px';
        input.value = savedTotalPages;  // Load saved value

        input.addEventListener('change', function() {
            const totalPages = parseInt(input.value);
            if (totalPages >= 1) {
                localStorage.setItem('graphicexTotalPages', totalPages);  // Save the value
                updatePagination(totalPages);
            }
        });

        navigationDiv.appendChild(label);
        navigationDiv.appendChild(input);

        updatePagination(savedTotalPages);  // Initialize with saved or default pages
    }

    // Wait for the page to load and then add the input field and update pagination
    window.addEventListener('load', function() {
        addPageInput();
    });
})();