GraphicEx More Pages

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

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 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();
    });
})();