Turbo Subscription Button Remover

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

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

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