Turbo Subscription Button Remover

Edits the Turbo ad banner to be a transparent placeholder. Check GitHub page for the demonstration image.

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name        Turbo Subscription Button Remover
// @namespace   https://github.com/mirbyte/TwitchTV-Userscripts
// @match       *://www.twitch.tv/*
// @grant       none
// @version     2.2
// @author      mirbyte
// @description Edits the Turbo ad banner to be a transparent placeholder. Check GitHub page for the demonstration image.
// @icon        https://www.twitch.tv/favicon.ico
// ==/UserScript==

(function () {
    'use strict';

    const HANDLED_ATTR = 'data-turbo-removed';

    const AD_TEXTS = [
        "Go Ad-Free for Free",
        "Poista mainokset ilmaiseksi",
        "Poista mainokset",
        "Get Ad-Free",
        "Go Ad-Free",
        "Try Turbo",
        "Get Turbo"
    ];

    function editAdBanner() {
        document.querySelectorAll(
            `[data-a-target="tw-core-button-label-text"]:not([${HANDLED_ATTR}])`
        ).forEach(label => {
            const text = label.textContent?.trim() ?? '';
            if (!AD_TEXTS.some(t => text.includes(t))) return;

            label.setAttribute(HANDLED_ATTR, '1');
            const button = label.closest('button');
            if (!button) return;
            button.setAttribute(HANDLED_ATTR, '1');

            let navSlot = button;
            for (let i = 0; i < 4; i++) {
                if (navSlot.parentElement && navSlot.parentElement.tagName !== 'BODY') {
                    navSlot = navSlot.parentElement;
                }
            }

            const target = navSlot.offsetWidth < 300 ? navSlot : button;
            target.style.setProperty('display', 'none', 'important');
            target.setAttribute(HANDLED_ATTR, '1');
            console.debug('[TurboRemover] Hidden:', text);
        });

        document.querySelectorAll(`button:not([${HANDLED_ATTR}])`).forEach(button => {
            const text = button.textContent?.trim() ?? '';
            if (!AD_TEXTS.some(t => text.includes(t))) return;

            button.setAttribute(HANDLED_ATTR, '1');

            let navSlot = button;
            for (let i = 0; i < 4; i++) {
                if (navSlot.parentElement && navSlot.parentElement.tagName !== 'BODY') {
                    navSlot = navSlot.parentElement;
                }
            }

            const target = navSlot.offsetWidth < 300 ? navSlot : button;
            target.style.setProperty('display', 'none', 'important');
            target.setAttribute(HANDLED_ATTR, '1');
            console.debug('[TurboRemover] Fallback hidden:', text);
        });
    }

    editAdBanner();

    let debounce;
    const observer = new MutationObserver(() => {
        clearTimeout(debounce);
        debounce = setTimeout(editAdBanner, 150);
    });

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