Direct Prompt Link Button

Puts a "Direct Link to Prompt" button on each prompt of an AO3 Prompt Meme.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Direct Prompt Link Button
// @namespace    https://greasyfork.org
// @version      1.1
// @description  Puts a "Direct Link to Prompt" button on each prompt of an AO3 Prompt Meme.
// @author       merelydovely
// @license      Creative Commons
// @match        http://archiveofourown.org/*/requests*
// @match        https://archiveofourown.org/*/requests*
// @run-at       document-idle
// @grant        none
// ==/UserScript==

(function() {

const buttonPacks = document.querySelectorAll("li.blurb.group ul.actions") //grabs all the unordered lists (packs of buttons) at the bottom of the prompt blurbs as a nodelist
//console.log(buttonPacks);
function addButton(thisPack) {
    if (thisPack.querySelector("form.button_to") == null) {
        return; //checks to see if there IS a claim button and skips this prompt blurb if there isn't one
    } else {
    let thisForm = thisPack.querySelector("form.button_to") //looks at the claim form of this specific prompt blurb and puts it in a variable
    let claimLink = new URL(thisForm.action, "https://archiveofourown.org"); //gets the realtive URL from the 'action' part of the claim form in the variable above (and puts the AO3 domain at the front for good measure)
    console.log(claimLink);
    let promptID = claimLink.searchParams.get("prompt_id"); //gets the prompt ID from the URL in the claim form 'action'
    //console.log(promptID);
    let promptLink = "prompts/"+promptID; //concatenates the prompt ID to the correct relative address for prompt pages
    let promptLinkCode = '<li><a href="'+promptLink+'">Link to prompt</a></li>' //create the HTML for a new button that links to the prompt page
    //console.log(promptLinkCode);
    thisPack.insertAdjacentHTML("beforeend", promptLinkCode); //put the HTML for the new button in at the end of this button pack on this prompt, as the final <li> inside the <ul>
    }
};
buttonPacks.forEach(addButton); //loop over every button pack in the buttonPacks nodelist and add a Link to Prompt button into each one

})()