Guest User

Untitled

a guest
Oct 29th, 2020
970
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*Run the Javascript code below in your console(or with TamperMonkey) and it will black out and mute ads
  2. whenever they play on Twitch.
  3. https://twitter.com/EthanShulman*/
  4. (function() {
  5.  
  6. //current state of if video is disabled
  7. var disabledVideo = null,
  8. originalVolume = 0;
  9.  
  10. //repeatedly check for ad
  11. function checkForAd() {
  12.  
  13.     //check ad by looking for text banner
  14.     var adBanner = document.querySelectorAll("span.tw-c-text-overlay"),
  15.         foundAd = false;
  16.     for (var i = 0; i < adBanner.length; i++) {
  17.         if (adBanner[i].attributes["data-test-selector"]) {
  18.             foundAd = true;
  19.             break;
  20.         }
  21.     }
  22.  
  23.     if (foundAd) {
  24.         //if found ad and video is visible, black out video and mute
  25.         if (!disabledVideo) {
  26.             //get livestream video element
  27.             var liveVid = document.getElementsByTagName("video");
  28.             if (liveVid.length) {
  29.                 disabledVideo = liveVid = liveVid[0];
  30.                 //mute
  31.                 originalVolume = liveVid.volume;
  32.                 liveVid.volume = 0;
  33.                 //black out
  34.                 liveVid.style.filter = "brightness(0%)";
  35.             }
  36.         }
  37.     } else {
  38.         //if no ad and video blacked out, unmute and disable black out
  39.         if (disabledVideo) {
  40.             disabledVideo.volume = originalVolume;
  41.             disabledVideo.style.filter = "";
  42.             disabledVideo = null;
  43.         }
  44.     }
  45.  
  46.     setTimeout(checkForAd,100);
  47. }
  48. checkForAd();
  49.  
  50. }());
Add Comment
Please, Sign In to add comment