GraphicEx More Pages

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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();
    });
})();