GGn Submit Both Edit Forms

Submit wiki and non-wiki forms together

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         GGn Submit Both Edit Forms
// @version      3
// @description  Submit wiki and non-wiki forms together
// @author       ingts
// @match        https://gazellegames.net/torrents.php?action=editgroup&groupid=*
// @namespace https://greasyfork.org/users/1141417
// ==/UserScript==

/** @type {HTMLFormElement[]} */
const formElements = [...document.querySelectorAll('#content form[action="torrents.php"]')]
formElements.length = 2

if (formElements[1]) {
    for (const formElement of formElements) {
        button(formElement.querySelector('input[type=submit]'))
    }
}

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

    input.onclick = async () => {
        if (!formElements[0].reportValidity() || !formElements[1].reportValidity()) return
        input.disabled = true
        const formDatas = [new FormData(formElements[0]), new FormData(formElements[1])]

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


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