[AO3] Better Work Buttons

Configure the buttons for works by hiding them.

当前为 2023-10-14 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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; }
                }
            }
        }
    }
})();