[AO3] Better Work Buttons

Configure the buttons for works by hiding them.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         [AO3] Better Work Buttons
// @namespace    https://greasyfork.org/en/users/1138163-dreambones
// @version      0.5.1
// @description  Configure the buttons for works by hiding them.
// @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": false,
        "Previous Chapter": false,
        "Next Chapter": false,
        "Chapter Index": false,
        "Bookmark": false,
        "Mark as Read": false,
        "Comments": false,
        "Hide Creator's Style": false,
        "Share": false,
        "Subscribe": false,
        "Download": false
    }

    var hideBottomButtons = {
        "Top": false,
        "Kudos": false,
        "Bookmark": false,
        "Mark as Read": false,
        "Comments": false,
    }
    //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 topBts = document.querySelector("ul.work.navigation.actions");
        var botBts = document.querySelector("ul[class='actions'][role='navigation']");

        for (let key in hideTopButtons) {
            if (hideTopButtons.hasOwnProperty(key)) {
                if (hideTopButtons[key] == true) {
                    try {
                        let button = topBts.querySelector(topButtons[key]);
                        button.remove();
                    }
                    catch (TypeError) { null; }
                }
            }
        }

        for (let key in hideBottomButtons) {
            if (hideBottomButtons.hasOwnProperty(key)) {
                if (hideBottomButtons[key] == true) {
                    try {
                        let button = botBts.querySelector(bottomButtons[key]).parentElement;
                        button.remove();
                    }
                    catch (TypeError) { null; }
                }
            }
        }
    }
})();