Twitch Ad blocker

Blocks All twitch ads 100% of the time! Never view another ad!

// ==UserScript==
// @name         Twitch Ad blocker
// @namespace    http://tampermonkey.net/
// @version      80.9
// @description  Blocks All twitch ads 100% of the time! Never view another ad!
// @author       NotYou (Gabriel Underwood)
// @match        https://www.twitch.tv/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    const CHECK_INTERVAL = 3000; // ms
    const AUTO_REFRESH = false;  // Set to true to auto-refresh stream on ad

    function log(msg) {
        console.log(`[TwitchAdBypass] ${msg}`);
    }

    function detectAd() {
        const adContainer = document.querySelector('.ad-banner__container,.tw-video-ad,.player-ad-overlay');

        // Twitch also adds a "purple screen" placeholder with this class sometimes
        const purpleScreen = document.querySelector('div[data-test-selector="video-player-ad-label"]');

        return adContainer || purpleScreen;
    }

    function mutePlayer() {
        const video = document.querySelector('video');
        if (video && !video.muted) {
            video.muted = true;
            log('Muted stream (ad detected)');
        }
    }

    function unmutePlayer() {
        const video = document.querySelector('video');
        if (video && video.muted) {
            video.muted = false;
            log('Unmuted stream (no ad)');
        }
    }

    function refreshPlayer() {
        const video = document.querySelector('video');
        if (video) {
            log('Refreshing stream (ad detected)');
            location.reload(); // reloads page — safer than trying to reload just the player
        }
    }

    setInterval(() => {
        const adIsPlaying = detectAd();

        if (adIsPlaying) {
            if (AUTO_REFRESH) {
                refreshPlayer();
            } else {
                mutePlayer();
            }
        } else {
            unmutePlayer();
        }
    }, CHECK_INTERVAL);
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址