// ==UserScript== // @name AO3: Links to First and Last Chapter // @namespace https://greasyfork.org/en/users/163551-vannius // @version 1.0 // @description Add links to first and last chapter to AO3. // @author Vannius // @match http*://archiveofourown.org/works/* // @exclude http*://archiveofourown.org/works/*view_full_work=true // @grant none // @downloadURL none // ==/UserScript== (function() { // selectedTag exists only when there are several chapters. const selectedTag = document.getElementById('selected_id'); if (!selectedTag) return; // Make hrefs to first and last chapter. const firstHref = window.location.href.split('/').slice(0, 6).join('/') + '/' + selectedTag.children[0].value; const lastHref = window.location.href.split('/').slice(0, 6).join('/') + '/' + selectedTag.children[selectedTag.children.length - 1].value; // Search location to add new link tags. const chapterIndexTag = document.getElementById('chapter_index').parentElement; const prevTags = chapterIndexTag.parentElement.getElementsByClassName('previous'); const nextTags = chapterIndexTag.parentElement.getElementsByClassName('next'); const navigationTags = document.getElementById('feedback').getElementsByClassName('actions'); // When '← Previous Chapter' exists if (prevTags.length){ // When '← Previous Chapter' != first chapter if(prevTags[0].firstChild.href != firstHref){ // Make a link tag to frist chapter const firstLiTag = document.createElement('li'); firstLiTag.className = 'chapter first'; const firstATag = document.createElement('a'); firstATag.href = firstHref; firstATag.appendChild(document.createTextNode('«')); firstLiTag.appendChild(firstATag); // Add the link tag to page's top prevTags[0].parentElement.insertBefore(firstLiTag.cloneNode(true), prevTags[0]); // Add the link tag to page's end for (let i=0; i