// ==UserScript== // @name AO3: Links to Last Chapter and Entire Works // @namespace https://greasyfork.org/en/users/163551-vannius // @version 2.0 // @license MIT // @description Add links to last chapter and entire works right after title of story. // @author Vannius // @match https://archiveofourown.org/* // @exclude /^https:\/\/archiveofourown\.org\/(collections\/[^/]+\/)?works\/\d+/ // @exclude /^https:\/\/archiveofourown\.org\/collections$/ // @exclude /^https:\/\/archiveofourown\.org\/collections(\?.+)$/ // @downloadURL none // ==/UserScript== (function () { // Main const articles = document.getElementsByClassName('blurb'); for (let article of articles) { // Scrape each article const headerTag = article.getElementsByClassName('header module')[0]; if (headerTag.className === "mystery header picture module") { continue; } const titleTag = headerTag.firstElementChild.firstElementChild; const series = titleTag.href.indexOf("/series/") !== -1; // When article isn't series page if (!series) { // Get last chapter const lastChapter = article.querySelector('dl .chapters > a'); // 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); } } } })();