AO3 Exchange Request Cut

Automatically collapses exchange request details

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        AO3 Exchange Request Cut
// @description Automatically collapses exchange request details
// @include     https://archiveofourown.org/collections/*/requests*
// @namespace   https://greasyfork.org/en/scripts/414224-ao3-exchange-request-cut
// @version     0.1
// @run-at      document-end
// ==/UserScript==


const requests = document.querySelectorAll("li.blurb.group")
const topBtnList = document.querySelector("ol.pagination.actions")
let hidden = true

const detailBtn = () => {
    const aBtn = document.createElement("button")
    aBtn.textContent = "Show Details"
    aBtn.className = "hide-exchange-button one"
    aBtn.style.margin = "5px"
    aBtn.addEventListener("click", function(){
        const summary = this.parentNode.querySelector("blockquote.userstuff.summary")
        if(summary.style.display === "none"){
            summary.style.display = "block"
            this.textContent = "Hide Details"
        }else{
            summary.style.display = "none"
            this.textContent = "Show Details"
        }
    })
    return aBtn
}

const showAll = () => {
    const aBtn = document.createElement("button")
    aBtn.textContent = "Show All"
    aBtn.className = "hide-exchange-button all"
    aBtn.style.margin = "5px"
    aBtn.addEventListener("click", function(){
        const summaries = document.querySelectorAll("blockquote.userstuff.summary")
        const buttons = document.querySelectorAll("button.hide-exchange-button.one")
        if(hidden){
            for(let i = 0; i < summaries.length; i++){
                summaries[i].style.display = "block"
                buttons[i].textContent = "Hide Details"
                this.textContent = "Hide All"
            }
            hidden = false
        }else{
            for(let i = 0; i < summaries.length; i++){
                summaries[i].style.display = "none"
                buttons[i].textContent = "Show Details"
                this.textContent = "Show All"
            }
            hidden = true
        }
    })
    return aBtn
}

for(let request of requests){
    const summary = request.querySelector("blockquote.userstuff.summary")
    if(summary !== null){
        summary.style.display = "none"
        request.insertBefore(detailBtn(), summary)
    }
}

topBtnList.appendChild(showAll())