I tried to use this code I found here in StackExchange to prevent advertisements sound on certain websites.
Array.prototype.slice.call(document.querySelectorAll('audio')).forEach((audio)=>{
audio.muted = true;
});
I implemented the code this way:
// ==UserScript==
// @name addicto
// @namespace nms
// @include http://*
// @include https://*
// @version 1
// @grant none
// ==/UserScript==
addEventListener('DOMContentLoaded', ()=>{
let sites = ['mako.co.il'];
let href = window.location.href;
for (let i = 0; i < sites.length; i++) {
if (href.includes(sites[i])) {
Array.prototype.slice.call(document.querySelectorAll('audio')).forEach((audio)=>{
audio.muted = true;
});
}
}
// If href includes the value of the iteration on the "sites" array, do stuff.
});
This didn't work and I still hear sounds from the site (mako.co.il). Maybe this is because the code doesn't work when the sound is coming from advertisement scripts?
If so, maybe a decent solution would be to disable any other script beside my scripts on the desired website? or maybe something else?