GazelleGames Batch Screenshot Processor

Perfectly integrated batch processor for PTPImg URLs on GazelleGames

目前為 2025-06-06 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         GazelleGames Batch Screenshot Processor
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Perfectly integrated batch processor for PTPImg URLs on GazelleGames
// @author       stormlight
// @match        https://gazellegames.net/torrents.php?action=editgroup&groupid=*
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';

    // Create batch processor UI
    function createBatchProcessor() {
        const container = document.createElement('div');
        container.style.flex = '1';
        container.style.marginLeft = '20px';
        container.style.marginTop = '5px'; // Align with screenshot fields

        container.innerHTML = `
            <div style="margin-bottom: 10px;">
                <textarea id="gg-batch-urls" rows="10" style="width: 80%; padding: 5px; border: 1px solid #ccc; font-family: inherit; font-size: 13px;" placeholder="Paste PTPImg URLs here, one per line"></textarea>
            </div>
            <input type="button" id="gg-process-btn" value="Fill Screenshot Fields">
        `;

        return container;
    }

    // Process URLs
    function processURLs(e) {
        e.preventDefault();

        const textarea = document.getElementById('gg-batch-urls');
        const urls = textarea.value.split('\n')
            .map(url => url.trim())
            .filter(url => url !== '');

        if (urls.length === 0) {
            alert('Please enter at least one URL');
            return;
        }

        // Get all existing fields
        const fields = document.querySelectorAll('#image_block input[name="screens[]"]');

        // Adjust field count if needed
        if (urls.length > fields.length) {
            const toAdd = urls.length - fields.length;
            for (let i = 0; i < toAdd; i++) {
                if (typeof AddScreenField === 'function') {
                    AddScreenField(true);
                } else {
                    // Fallback method
                    const newField = document.createElement('span');
                    newField.innerHTML = `<br><input type="text" name="screens[]" style="width: 90%;"><input type="button" value="PTPImg It">`;
                    document.getElementById('image_block').appendChild(newField);
                }
            }
        } else if (urls.length < fields.length) {
            const toRemove = fields.length - urls.length;
            for (let i = 0; i < toRemove; i++) {
                if (typeof RemoveScreenField === 'function') {
                    RemoveScreenField();
                } else {
                    // Fallback method
                    const fields = document.querySelectorAll('#image_block span');
                    if (fields.length > 1) {
                        fields[fields.length - 1].remove();
                    }
                }
            }
        }

        // Populate fields
        const inputs = document.querySelectorAll('#image_block input[name="screens[]"]');
        for (let i = 0; i < urls.length; i++) {
            if (i < inputs.length) {
                inputs[i].value = urls[i];
            }
        }
    }

    // Main function to set up the UI
    function init() {
        const imageBlock = document.getElementById('image_block');
        if (!imageBlock) return;

        // Create container for the row layout
        const wrapper = document.createElement('div');
        wrapper.style.display = 'flex';
        wrapper.style.gap = '20px';
        wrapper.style.marginTop = '5px'; // Reduced to match site spacing

        // Wrap the image block
        const screenshotsColumn = document.createElement('div');
        screenshotsColumn.style.flex = '1.2'; // Slightly wider than processor
        screenshotsColumn.appendChild(imageBlock);

        // Create the batch processor
        const batchColumn = createBatchProcessor();

        // Add both columns to the wrapper
        wrapper.appendChild(screenshotsColumn);
        wrapper.appendChild(batchColumn);

        // Find the best insertion point
        const screenshotsHeader = [...document.querySelectorAll('h3')].find(h3 =>
            h3.textContent.includes('Screenshots')
        );

        if (screenshotsHeader) {
            // Insert after the header but before any existing content
            const parent = screenshotsHeader.parentNode;
            parent.insertBefore(wrapper, screenshotsHeader.nextSibling);
        } else {
            // Fallback to inserting before the image block
            imageBlock.parentNode.insertBefore(wrapper, imageBlock);
        }

        // Add event listener to the process button
        document.getElementById('gg-process-btn').addEventListener('click', processURLs);
    }

    // Run the script
    setTimeout(init, 500);
})();