Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Run the Javascript code below in your console(or with TamperMonkey) and it will black out and mute ads
- whenever they play on Twitch.
- https://twitter.com/EthanShulman*/
- (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%)";
- }
- }
- } else {
- //if no ad and video blacked out, unmute and disable black out
- if (disabledVideo) {
- disabledVideo.volume = originalVolume;
- disabledVideo.style.filter = "";
- disabledVideo = null;
- }
- }
- setTimeout(checkForAd,100);
- }
- checkForAd();
- }());
Add Comment
Please, Sign In to add comment