Last active
July 29, 2024 02:39
-
-
Save t0rr3sp3dr0/af7824f6968e5190d276507fa7ac603c to your computer and use it in GitHub Desktop.
Block Ads on Hulu via UserScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Hulu AdBlocker | |
// @namespace https://gist.github.com/t0rr3sp3dr0 | |
// @version 0.0.1 | |
// @author t0rr3sp3dr0 | |
// @description Block Ads on Hulu | |
// @updateURL https://gist.github.com/t0rr3sp3dr0/af7824f6968e5190d276507fa7ac603c/raw | |
// @downloadURL https://gist.github.com/t0rr3sp3dr0/af7824f6968e5190d276507fa7ac603c/raw | |
// @match https://www.hulu.com/* | |
// @run-at document-end | |
// @grant GM_addStyle | |
// ==/UserScript== | |
if (!GM_addStyle) | |
GM_addStyle = css => { | |
const style = document.createElement('style'); | |
style.type = 'text/css'; | |
style.innerHTML = css; | |
document.head.appendChild(style); | |
}; | |
(() => { | |
GM_addStyle(` | |
.AdPlayer { | |
display: none !important; | |
} | |
`); | |
const installedAdBlockers = { | |
null: true, | |
undefined: true, | |
}; | |
const installAdBlocker = () => { | |
const ph = document.querySelector('.Timeline__playhead'); | |
if (installedAdBlockers[ph]) | |
return; | |
new MutationObserver(mutations => mutations.forEach(mutation => { | |
if (mutation.target.classList.contains('Timeline__playhead--ad')) | |
document.querySelector('#content-video-player').play(); | |
})) | |
.observe( | |
ph, | |
{ | |
attributes: true, | |
}, | |
); | |
installedAdBlockers[ph] = true; | |
}; | |
setInterval(installAdBlocker, 1000); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment