AO3: Links for Entire Works

Add links to next and previous chapter to Entire Works of AO3.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         AO3: Links for Entire Works
// @namespace    https://greasyfork.org/en/users/163551-vannius
// @version      1.5
// @license      MIT
// @description  Add links to next and previous chapter to Entire Works of AO3.
// @author       Vannius
// @match        https://archiveofourown.org/works/*view_full_work=true*
// @grant        none
// ==/UserScript==

(function() {
    // get id="chapter-[d]+" tags
    let chapters = [];
    let index = 1;
    while (true) {
        const chapter = document.getElementById('chapter-' + index);
        if (chapter) {
            chapters.push(chapter);
            index += 1;
        } else {
            break;
        }
    }

    for (let i = 0; i < chapters.length; i++) {
        // Display add links to right of each chapter title.
        const rightSpan = document.createElement('span');
        rightSpan.style.float = 'right';

        // Make a link to current chapter
        if (i === 0) {
            const currentChapter = document.createElement('a');
            currentChapter.title = "Current chapter";
            currentChapter.href = "#chapter-" + (i + 1);
            currentChapter.appendChild(document.createTextNode('◆'));
            rightSpan.appendChild(currentChapter);
        }
        // Make a link to prev chapter
        if (i !== 0) {
            const prevChapter = document.createElement('a');
            prevChapter.title = "Previous chapter";
            prevChapter.href = "#chapter-" + i;
            prevChapter.appendChild(document.createTextNode('▲'));
            rightSpan.appendChild(prevChapter);
        }
        // Make a link to next chapter
        if (i != chapters.length - 1) {
            const nextChapter = document.createElement('a');
            nextChapter.title = "Next chapter";
            nextChapter.href = "#chapter-" + (i + 2);
            nextChapter.appendChild(document.createTextNode('▼'));
            rightSpan.appendChild(nextChapter);
        }
        // Make a link to current chapter
        if (i == chapters.length - 1) {
            const currentChapter = document.createElement('a');
            currentChapter.title = "Current chapter";
            currentChapter.href = "#chapter-" + (i + 1);
            currentChapter.appendChild(document.createTextNode('◆'));
            rightSpan.appendChild(currentChapter);
        }

        // Add links
        chapters[i].querySelector(".chapter .title").appendChild(rightSpan);
    }
})();