GazelleGames Batch Screenshot Processor

Perfectly integrated batch processor for PTPImg URLs on GazelleGames

当前为 2025-06-06 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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);
})();