Turbo Subscription Button Remover

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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
    });
})();