Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save andersonbosa/1303f8ac248e98ad9ae151e39ed0bbb4 to your computer and use it in GitHub Desktop.
Save andersonbosa/1303f8ac248e98ad9ae151e39ed0bbb4 to your computer and use it in GitHub Desktop.
automute youtube on video ads
// ==UserScript==
// @name automute youtube on video ads
// @namespace http://tampermonkey.net/
// @description try to take over the world!
// @author You
// @match https://www.youtube.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant none
// ==/UserScript==
(function() {
'use strict';
const getMuteButton = () => document.querySelector("#movie_player > div.ytp-chrome-bottom > div.ytp-chrome-controls > div.ytp-left-controls > span > button").click()
const hasVideoAds = () => Boolean(document.querySelector("#ad-avatar-lockup-card\\:z"))
const isMuted = () => {
return getMuteButton().title.toLowerCase().includes('reativar')
}
const mute = () => !isMuted() && getMuteButton().click()
const unmute = () => isMuted && getMuteButton().click()
function main () {
if (hasVideoAds()) {
mute()
} else {
unmute()
}
}
setInterval(main, 250)
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment