AO3 Exchange Request Cut

Automatically collapses exchange request details

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==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())