Skip to content

Instantly share code, notes, and snippets.

@goto-dev-null
Last active July 26, 2019 19:58
Show Gist options
  • Save goto-dev-null/8aedfa7cc89b12f43ce5928aca1855f8 to your computer and use it in GitHub Desktop.
Save goto-dev-null/8aedfa7cc89b12f43ce5928aca1855f8 to your computer and use it in GitHub Desktop.
Hulu auto-muter for ads

This is a JS function to automatically mute Hulu when an ad comes on, then unmute it when the show comes back. It works a of 7/26/2019.

To create a bookmarklet, create a new bookmark starting with javascript:, then the contents of minified.js.

window.huluAdTimer = window.huluAdTimer || setInterval(function() { let volBtn = document.getElementsByClassName('controls__volume-button')[0], isMuted = volBtn.classList.contains('controls__volume-button--mute'), isAdbreak = document.getElementsByClassName('ad-container')[0].style.display=="block"; if((isAdbreak && !isMuted) || (!isAdbreak && isMuted)) volBtn.click(); }, 1000)
// Here is an un-minified version
function muteAd() {
let volBtn = document.getElementsByClassName('controls__volume-button')[0];
let isMuted = volBtn.classList.contains('controls__volume-button--mute');
let isAdbreak = document.getElementsByClassName('ad-container')[0].style.display=="block";
let needsMute = isAdbreak && !isMuted;
let needsUnmute = !isAdbreak && isMuted;
if(needsMute || needsUnmute)
volBtn.click();
console.log("is " + (isAdbreak ? "" : "not ") + "ad");
console.log("is " + (isMuted ? "" : "not ") + "muted");
if(needsMute)
console.log("muting");
else if(needsUnmute)
console.log("unmuting");
else
console.log("doing nothing");
}
let timerId = setInterval(muteAd, 1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment