Skip to content

Instantly share code, notes, and snippets.

@lassekongo83
Last active January 21, 2024 09:17
Show Gist options
  • Save lassekongo83/a9a31cde37ac3aecbe5eebba3180e35e to your computer and use it in GitHub Desktop.
Save lassekongo83/a9a31cde37ac3aecbe5eebba3180e35e to your computer and use it in GitHub Desktop.
Modified script from https://pastebin.com/HS9ukpRm
// ==UserScript==
// @name Twitch ad blackout
// @namespace Twitch ad blackout
// @match *://*.twitch.tv/*
// @grant none
// @version 1.0
// @author https://nitter.net/EthanShulman/
// ==/UserScript==
// Modified script from https://pastebin.com/HS9ukpRm
(function() {
//current state of if video is disabled
var disabledVideo = null,
originalVolume = 0;
//repeatedly check for ad
function checkForAd() {
//check ad by looking for text banner
var adBanner = document.querySelectorAll("span.tw-c-text-overlay"),
foundAd = false;
for (var i = 0; i < adBanner.length; i++) {
if (adBanner[i].attributes["data-test-selector"]) {
foundAd = true;
break;
}
}
if (foundAd) {
//if found ad and video is visible, black out video and mute
if (!disabledVideo) {
//get livestream video element
var liveVid = document.getElementsByTagName("video");
if (liveVid.length) {
disabledVideo = liveVid = liveVid[0];
//mute
originalVolume = liveVid.volume;
liveVid.volume = 0;
//black out
liveVid.style.filter = "brightness(0%)";
//speed up
document.querySelector('video').playbackRate = 16.0;
}
}
} else {
//if no ad and video blacked out, unmute and disable black out
if (disabledVideo) {
disabledVideo.volume = originalVolume;
disabledVideo.style.filter = "";
disabledVideo = null;
document.querySelector('video').playbackRate = 1.0;
}
}
setTimeout(checkForAd,100);
}
checkForAd();
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment