YouTube - FIXED remove download, clip, thanks buttons

Hides YouTube "Download", "Clip", "Thanks", and "Promote" buttons from the interface. Fixed.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         YouTube - FIXED remove download, clip, thanks buttons
// @namespace    Violentmonkey Scripts
// @version      1.0
// @description  Hides YouTube "Download", "Clip", "Thanks", and "Promote" buttons from the interface. Fixed.
// @author       Magma_Craft (update by jawsawn)
// @match        *://www.youtube.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    "use strict";

    const style = document.createElement("style");
    style.textContent = `
        ytd-download-button-renderer,
        #flexible-item-buttons [aria-label="Promote"],
        #flexible-item-buttons [aria-label="Clip"],
        #flexible-item-buttons [aria-label="Thanks"],
        #flexible-item-buttons [title="Show support with Super Thanks"],
        ytd-button-renderer[button-renderer*="MONEY_HEART"],
        ytd-button-renderer[button-renderer*="CONTENT_CUT"] {
            display: none !important;
        }
    `;
    document.head.appendChild(style);
    //uncomment the rest if it breaks again

    /*function removeButtonsByIconType(container) {
        const buttons = container.querySelectorAll("ytd-button-renderer");

        buttons.forEach((btn) => {
            try {
                const iconType = btn.data?.icon?.iconType;
                if (["MONEY_HEART", "CONTENT_CUT", "DOWNLOAD"].includes(iconType)) {
                    btn.remove();
                }
            } catch (e) {
                // fail silently
            }
        });
    }

    async function waitForElm(selector) {
        while (!document.querySelector(selector)) {
            await new Promise((resolve) => requestAnimationFrame(resolve));
        }
        return document.querySelector(selector);
    }

    function initObserver() {
        const observer = new MutationObserver(() => {
            document.querySelectorAll("#top-level-buttons-computed.ytd-menu-renderer")
                .forEach(removeButtonsByIconType);
        });

        observer.observe(document.body, {
            childList: true,
            subtree: true,
        });
    }

    document.addEventListener("yt-page-data-updated", async () => {
        const btns = await waitForElm("#top-level-buttons-computed.ytd-menu-renderer");
        removeButtonsByIconType(btns);
    });

    initObserver();*/
})();