AO3: Links to Last Chapter and Entire Works

Add links to last chapter and entire works right after title of story.

< Feedback on AO3: Links to Last Chapter and Entire Works

Review: Good - script works

§
Posted: 2020-12-31

Thank you for this! I was wondering if it would be possible to make the Entire work link appear even if it's only one chapter to make it easier to save to Instapaper/Pocket? I can edit the script so it also appends view_adult=true myself, but don't know how to make it appear on single chapter works. Thanks either way!

VanniusAuthor
§
Posted: 2020-12-31
Edited: 2020-12-31

Hi, thank you for using this script. Please edit the script according to the following instruction.

The edited script adds a link with view_full_work=true and view_adult=true. If there is only one chapter, add a link with view_adult=true.

Let me know if there is a problem.

Replace if (lastChapter) {...}

            // When lastChapter is a link
            if (lastChapter) {
                // Get href
                const spritedHref = titleTag.href.split('/');
                const href = spritedHref[3] === 'collections'
                    ? spritedHref.slice(0, 3).concat(spritedHref.slice(5)).join('/') : titleTag.href;

                // Make link to entire contents
                const entireLink = document.createElement('a');
                entireLink.href = href + "?view_full_work=true";
                entireLink.title = "Entire Contents";
                entireLink.appendChild(document.createTextNode('E'));

                // Make link button to last chapter.
                const lastLink = document.createElement('a');
                lastLink.href = lastChapter.href;
                lastLink.title = "Last Chapter";
                lastLink.appendChild(document.createTextNode('L'));

                // Add link to entire contents and link button to last chapter right after title of story.
                const fragment = document.createDocumentFragment();
                fragment.appendChild(document.createTextNode(' '));
                fragment.appendChild(entireLink);
                fragment.appendChild(document.createTextNode(' '));
                fragment.appendChild(lastLink);

                titleTag.parentNode.insertBefore(fragment, titleTag.nextSibling);
            }

with

            // Get href
            const spritedHref = titleTag.href.split('/');
            const href = spritedHref[3] === 'collections'
                ? spritedHref.slice(0, 3).concat(spritedHref.slice(5)).join('/') : titleTag.href;

            // Make link to entire contents
            const parameters = [];
            if (lastChapter) {
                parameters.push("view_full_work=true");
            }
            const ratingTags = article.querySelectorAll('.rating-explicit, .rating-mature, .rating-notrated');
            if ([...ratingTags].length) {
                parameters.push("view_adult=true");
            }

            const entireLink = document.createElement('a');
            entireLink.href = href + '?' + parameters.join('&');
            entireLink.title = "Entire Contents";
            entireLink.appendChild(document.createTextNode('E'));

            // Add link to entire contents.
            const fragment = document.createDocumentFragment();
            fragment.appendChild(document.createTextNode(' '));
            fragment.appendChild(entireLink);

            // When lastChapter is a link
            if (lastChapter) {
                // Make link to last chapter.
                const lastLink = document.createElement('a');
                lastLink.href = lastChapter.href;
                lastLink.title = "Last Chapter";
                lastLink.appendChild(document.createTextNode('L'));

                // Add link to last chapter.
                fragment.appendChild(document.createTextNode(' '));
                fragment.appendChild(lastLink);
            }

            // Add link to entire contents and link to last chapter right after title of story.
            titleTag.parentNode.insertBefore(fragment, titleTag.nextSibling);
        }
§
Posted: 2021-01-09

Thank you so much!! It works perfectly! Sorry for the delayed reply, I thought I would get an email if you responded but I didn't. Thanks again for your help!! It's so nice of you :)

Post reply

Sign in to post a reply.