GGn Collection Removal Buttons

Adds buttons to each row in the main collection list for easy removal

// ==UserScript==
// @name         GGn Collection Removal Buttons
// @namespace    none
// @version      1
// @description  Adds buttons to each row in the main collection list for easy removal
// @author       ingts
// @match        https://gazellegames.net/torrents.php?id=*
// ==/UserScript==
const collections = document.getElementById('collages')
if (collections) {
    collections.querySelectorAll('tr:not(.colhead)').forEach(tr => {
        tr.style.position = 'relative'
        const button = document.createElement('button')
        button.type = 'button'
        Object.assign(button.style, {
            position: 'absolute',
            top: '2px',
            right: '3px',
            filter: 'opacity(0.8)'
        })
        button.textContent = 'X'
        tr.append(button)
        button.onclick = () => {
            button.disabled = true
            const groupId = new URL(location.href).searchParams.get('id')
            const collectionId = /\d+/.exec(tr.querySelector('a').href)[0]
            fetch('collections.php', {
            method: 'post',
            headers: {'Content-Type': 'application/x-www-form-urlencoded'},
            body: `action=manage_handle&auth=${authkey}&collageid=${collectionId}&remove[]=${groupId}&submit=Remove`
            })
                .then(r => {
                    if (!(r.ok && r.redirected)) {
                        button.disabled = false
                        throw Error
                    }
                    button.textContent = '✓'
                })
                .catch(() => {
                    alert(`Failed to remove collection ID ${collectionId}`)
                })
        }
    })
}