AO3: Link to Entire Works

Add links to entire works right after title of story.

Tính đến 18-12-2017. Xem phiên bản mới nhất.

// ==UserScript==
// @name         AO3: Link to Entire Works
// @namespace    https://greasyfork.org/en/users/163551-vannius
// @version      1.0
// @description  Add links to entire works right after title of story.
// @author       Vannius
// @match       http*://archiveofourown.org/works/*
// @match       http*://archiveofourown.org/tags/*/works*
// @match       http*://archiveofourown.org/works?*
// @match       http*://archiveofourown.org/series/*
// @match       http*://archiveofourown.org/bookmarks*
// @match       http*://archiveofourown.org/users/*
// @grant        none
// ==/UserScript==

(function() {
    // Scrape data
    const articles = document.getElementsByClassName('blurb');

    for (let article of articles){
        // Scrape each article
        const titleTag = article.getElementsByClassName('heading')[0].firstChild.nextElementSibling;
        const originalHref = titleTag.href;
        const series = (originalHref.indexOf("/series/") != -1) ? true : false;

        // When article isn't series page
        if (!series){
            const chapters = article.getElementsByTagName('dl')[0].getElementsByClassName('chapters')[1].textContent.split("/");
            // When chapter number isn't one
            if (chapters[0] != '1'){
                // Make link element
                const addLink = document.createElement('a');
                addLink.href = originalHref + "?view_full_work=true";
                addLink.appendChild(document.createTextNode('E'));

                // Add link element right after title of story.
                titleTag.parentElement.insertBefore(addLink, titleTag.nextSibling);
                // Adjust placement of addLink.
                titleTag.parentElement.insertBefore(document.createTextNode(' '), addLink);
            }
        }
    }
})();