Twitch Ad Blocker & Stream Helper

Automatically blocks Twitch video ads by replacing the player with an embedded version, and notifies user when ads are skipped. Built and optimized by Domopremo.

Tendrás que instalar una extensión para tu navegador como Tampermonkey, Greasemonkey o Violentmonkey si quieres utilizar este script.

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

Necesitarás instalar una extensión como Tampermonkey o Violentmonkey para instalar este script.

Necesitarás instalar una extensión como Tampermonkey o Userscripts para instalar este script.

Necesitará instalar una extensión como Tampermonkey para instalar este script.

Necesitarás instalar una extensión para administrar scripts de usuario si quieres instalar este script.

(Ya tengo un administrador de scripts de usuario, déjame instalarlo)

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

(Ya tengo un administrador de estilos de usuario, déjame instalarlo)

// ==UserScript==
// @name         Twitch Ad Blocker & Stream Helper
// @namespace    DomopremoScripts
// @version      1.0.0
// @description  Automatically blocks Twitch video ads by replacing the player with an embedded version, and notifies user when ads are skipped. Built and optimized by Domopremo.
// @author       Domopremo
// @match        https://www.twitch.tv/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    function showPopup(msg) {
        const box = document.createElement('div');
        box.textContent = msg;
        box.style = 'position:fixed;top:10px;right:10px;background:#000;color:#0f0;padding:8px;font-family:monospace;z-index:99999;border:1px solid #0f0;box-shadow:0 0 10px #0f0;';
        document.body.appendChild(box);
        setTimeout(() => box.remove(), 3000);
    }

    function replacePlayerWithEmbed() {
        const videoPlayer = document.querySelector('div.video-player__container');
        if (!videoPlayer) return;

        const channel = window.location.pathname.split('/')[1];
        if (!channel) return;

        const iframe = document.createElement('iframe');
        iframe.src = `https://player.twitch.tv/?channel=${channel}&parent=twitch.tv&autoplay=true`;
        iframe.height = "100%";
        iframe.width = "100%";
        iframe.allowFullscreen = true;
        iframe.style = "border:none; position:absolute; top:0; left:0; height:100%; width:100%; z-index:9999;";

        iframe.onerror = () => {
            console.warn("Twitch embed iframe failed. Reloading...");
            location.reload();
        };

        // Clear original player
        videoPlayer.innerHTML = '';
        videoPlayer.appendChild(iframe);

        showPopup("Twitch Ad Blocked and Replaced with Embed");
    }

    function monitorForAds() {
        const observer = new MutationObserver(() => {
            const adBanner = document.querySelector('[data-a-target="video-ad-label"]');
            if (adBanner) {
                console.log("Ad detected. Replacing player...");
                replacePlayerWithEmbed();
            }
        });

        observer.observe(document.body, { childList: true, subtree: true });
    }

    window.addEventListener('load', () => {
        setTimeout(() => {
            monitorForAds();
            console.log("Twitch Ad Blocker Loaded by DomopremoScripts");
        }, 3000);
    });
})();