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.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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