Greasy Fork 还支持 简体中文。

Twitch Ad blocker

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

Från och med 2025-06-02. Se den senaste versionen.

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