Greasy Fork is available in English.

GGn Multi Submit Edit Forms

Submit all changed edit forms together

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

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램을 설치해야 합니다.

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

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

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

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         GGn Multi Submit Edit Forms
// @version      4
// @description  Submit all changed edit forms together
// @author       ingts
// @match        https://gazellegames.net/torrents.php?action=editgroup&groupid=*
// @namespace https://greasyfork.org/users/1141417
// ==/UserScript==

/** @type {HTMLFormElement[]} */
const forms = [...document.querySelectorAll('#content form[action="torrents.php"]')]
const origFormDatas = forms.map(f => new FormData(f))

for (const formElement of forms) {
    addButton(formElement.querySelector('input[type=submit]'))
}

function addButton(insert) {
    const input = document.createElement('input')
    input.type = 'button'
    input.value = 'Multi Submit'
    input.style.marginLeft = '5px'
    insert.insertAdjacentElement('afterend', input)

    const changed = []

    input.onclick = async () => {
        for (let i = 0; i < forms.length; i++) {
            if (!forms[i].reportValidity()) {
                forms[i].scrollIntoView()
                return
            }
            const formData = new FormData(forms[i])
            if (new URLSearchParams(origFormDatas[i]).toString() !== new URLSearchParams(formData).toString())
                changed.push(formData)
        }

        const fetches = changed.map((fd, index) => {
            fetch('torrents.php', {
                method: 'POST',
                body: fd,
            }).then(r => {
                if (!(r.ok && r.redirected)) {
                    console.error(r)
                    input.disabled = false
                    input.value = 'Multi Submit'
                    alert(`Failed to submit ${index === 0 ? 'wiki' : index === 1 ? 'non-wiki' : 'rename'} form`)
                    throw new Error()
                }
            })
        })

        input.disabled = true
        input.value = 'Submitting'

        Promise.all(fetches).then(() => {
            setTimeout(() => {
                location.href = `https://gazellegames.net/torrents.php?id=${/\d+/.exec(location.href)[0]}`
            }, 1000)
        })
    }
}