Created
January 8, 2025 19:27
-
-
Save andersonbosa/1303f8ac248e98ad9ae151e39ed0bbb4 to your computer and use it in GitHub Desktop.
automute youtube on video ads
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 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