[AO3] Better Work Buttons

Configure the buttons for works by hiding or rearranging their order.

目前為 2023-10-14 提交的版本,檢視 最新版本

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

You will need to install an extension such as Tampermonkey to install this script.

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         [AO3] Better Work Buttons
// @namespace    https://greasyfork.org/en/users/1138163-dreambones
// @version      0.6
// @description  Configure the buttons for works by hiding or rearranging their order.
// @author       DREAMBONES
// @match        http*://archiveofourown.org/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=archiveofourown.org
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Configure here! Set to "true" if you want the button hidden, "false" if you want it to be seen.
    var hideTopButtons = {
        "Entire Work": true,
        "Previous Chapter": false,
        "Next Chapter": false,
        "Chapter Index": false,
        "Bookmark": true,
        "Mark as Read": false,
        "Comments": true,
        "Hide Creator's Style": true,
        "Share": true,
        "Subscribe": false,
        "Download": false
    }

    var hideBottomButtons = {
        "Top": true,
        "Kudos": false,
        "Bookmark": false,
        "Mark as Read": false,
        "Comments": false,
    }

    var topButtonPos = ["Entire Work", "Previous Chapter", "Chapter Index", "Next Chapter", "Bookmark", "Mark as Read", "Subscribe", "Comments", "Share", "Download", "Hide Creator's Style"]
    var bottomButtonPos = ["Top", "Kudos", "Bookmark", "Mark as Read", "Comments"]
    //Config ends here!

    var topButtons = {
        "Entire Work": "li.chapter.entire",
        "Previous Chapter": "li.chapter.previous",
        "Next Chapter": "li.chapter.next",
        "Chapter Index": "li[class='chapter']",
        "Bookmark": "li[class='bookmark']",
        "Mark as Read": "li[class='mark']",
        "Comments": "li[class='comments']",
        "Hide Creator's Style": "li[class='style']",
        "Share": "li[class='share']",
        "Subscribe": "li[class='subscribe']",
        "Download": "li[class='download']"
    }

    var bottomButtons = {
        "Top": "li > a[href='#main']",
        "Kudos": "li > form[id='new_kudo']",
        "Bookmark": "li > a[href='#bookmark-form']",
        "Mark as Read": "li > a[href$='mark_as_read']",
        "Comments": "li > a[href^='/comments/']",
    }

    var domainRe = /https?:\/\/archiveofourown\.org\/works\/\d+/i
    if (domainRe.test(document.URL)) {
        var topRow = document.querySelector("ul.work.navigation.actions");
        var bottomRow = document.querySelector("ul[class='actions'][role='navigation']");

        arrangeButtons(topRow, topButtons, topButtonPos);
        arrangeButtons(bottomRow, bottomButtons, bottomButtonPos);

        toggleButtons(topRow, topButtons, hideTopButtons);
        toggleButtons(bottomRow, bottomButtons, hideBottomButtons);
    }

    function arrangeButtons(obj, array, settings) {
        for (let i = 0; i < (settings.length); i++) {
            try {
                let button = obj.querySelector(array[settings[i]]);
                if (button.nodeName != "LI") { button = button.parentElement; }
                obj.insertBefore(button, obj.children[i]);
            }
            catch (TypeError) { null; }
        }
    }

    function toggleButtons(obj, array, settings) {
        for (let key in settings) {
            if (settings.hasOwnProperty(key)) {
                if (settings[key] == true) {
                    try {
                        let button = obj.querySelector(array[key]);
                        if (button.nodeName != "LI") { button = button.parentElement; }
                        button.remove();
                    }
                    catch (TypeError) { null; }
                }
            }
        }
    }
})();