Blocks All twitch ads 100% of the time! Never view another ad!
当前为
// ==UserScript==
// @name Twitch Ad blocker
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Blocks All twitch ads 100% of the time! Never view another ad!
// @author You
// @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);
})();