Turbo Subscription Button Remover

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Turbo Subscription Button Remover
// @namespace   https://github.com/mirbyte/TwitchTV-Userscripts/edit/main/Turbo%20Subscription%20Button%20Remover.js
// @match       *://www.twitch.tv/*
// @grant       none
// @version     2.0
// @author      mirbyte
// @description Edits the Turbo ad banner to be a transparent placeholder. Check GitHub page for the demonstration image.
// @icon        https://banner2.cleanpng.com/20180513/xie/kisspng-twitch-computer-icons-logo-5af8037d689af0.0981376915262032614285.jpg
// ==/UserScript==

(function() {
    'use strict';

    function editAdBanner() {
        // More robust selector approach
        const adButtons = document.querySelectorAll('button, [role="button"]');
        const adButtonTexts = [
            "Go Ad-Free for Free",
            "Poista mainokset ilmaiseksi", 
            "Poista mainokset",
            "Get Ad-Free",
            "Go Ad-Free",
            "Try Turbo",
            "Get Turbo"
            // add more here
        ];

        adButtons.forEach(button => {
            const buttonText = button.textContent?.trim();
            if (buttonText && adButtonTexts.some(text => buttonText.includes(text))) {
                // Look for parent containers with multiple approaches
                let container = button.closest('[class*="Layout"]') || 
                               button.closest('[class*="InjectLayout"]') ||
                               button.closest('[class*="Banner"]') ||
                               button.closest('[class*="Ad"]');
                
                if (container && container.offsetHeight > 20) {
                    container.style.cssText = `
                        background: transparent !important;
                        border: none !important;
                        padding: 0 !important;
                        margin: 0 !important;
                        height: 0 !important;
                        overflow: hidden !important;
                        opacity: 0 !important;
                    `;
                    console.log("Turbo Subscription Banner hidden:", buttonText);
                }
            }
        });

        // Also target by aria-label or data attributes
        const ariaButtons = document.querySelectorAll('[aria-label*="ad"], [aria-label*="Ad"], [aria-label*="turbo"], [aria-label*="Turbo"]');
        ariaButtons.forEach(button => {
            const container = button.closest('[class*="Layout"], [class*="Banner"], [class*="Ad"]');
            if (container) {
                container.style.display = 'none';
            }
        });
    }

    // Run initially
    editAdBanner();

    // Enhanced observer with better performance
    let observerTimeout;
    const observer = new MutationObserver(function(mutations) {
        clearTimeout(observerTimeout);
        observerTimeout = setTimeout(editAdBanner, 100);
    });
    
    if (document.body) {
        observer.observe(document.body, { 
            subtree: true, 
            childList: true,
            attributes: true,
            attributeFilter: ['class', 'style']
        });
    }
})();