Turbo Subscription Button Remover

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

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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']
        });
    }
})();