GGn PTPImg Enforcer

Disable submit unless images use ptpimg.me and album_desc has proper format.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         GGn PTPImg Enforcer
// @namespace    https://greasyfork.org/users/1395131
// @version      2.1.0
// @author       SleepingGiant
// @description  Disable submit unless images use ptpimg.me and album_desc has proper format.
// @require      https://update.greasyfork.org/scripts/533781/1578387/GGn%20Upload%20Blocker%20Manager.js
// @include      https://gazellegames.net/upload.php*
// @match        https://gazellegames.net/torrents.php?action=editgroup*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    const COVER_SEL = 'input[name="image"]';
    const SCREENSHOTS_SEL = '#image_block input[name="screens[]"]';
    const REASON_TEXT = 'All images must be hosted on ptpimg.me.';

    function isValidImageURL(url) {
        return url.includes('ptpimg.me');
    }

    // The first 4 must be present AND valid.
    // After that, each must be present OR valid
    function hasFourValidURLs(inputs) {
        const arr = Array.from(inputs);
        if (arr.length < 4) return false;
        for (let i = 0; i < 4; i++) {
            const val = arr[i].value.trim();
            if (!val || !isValidImageURL(val)) {
                return false;
            }
        }

        for (let i = 4; i < arr.length; i++) {
            const val = arr[i].value.trim();
            if (!(isValidImageURL(val) || val === '')) {
                return false;
            }
        }
        return true;
    }

    function allURLsValid() {
        const cover = document.querySelector(COVER_SEL);
        if (!cover || !isValidImageURL(cover.value.trim())) return false;

        const screenshotInputs = document.querySelectorAll(SCREENSHOTS_SEL);
        if (!hasFourValidURLs(screenshotInputs)) return false;

        return true;
    }

    function refresh(mgr) {
        if (!allURLsValid()) {
            mgr.addReason(REASON_TEXT);
        } else {
            mgr.removeReason(REASON_TEXT);
        }
    }

    const finder = setInterval(() => {
        if (document.readyState !== 'complete') return;

        const submitBtn = document.querySelector('#post, input[type="submit"][value="Submit"]');
        if (!submitBtn) return;

        const mgr = new UploadBlockerManager(submitBtn);
        mgr.attachOverrideCheckbox();

        clearInterval(finder);

        setInterval(() => refresh(mgr), 500);
    }, 500);
})();