Untitled
user_2795378
plain_text
a year ago
1.3 kB
7
Indexable
document.addEventListener("DOMContentLoaded", function() { // Function to mute all videos function muteAllVideos() { const videos = document.querySelectorAll('video'); videos.forEach(video => { video.muted = true; }); } // Run the function once the DOM is fully loaded muteAllVideos(); // Optionally, you can observe for new video elements being added to the DOM and mute them as well const observer = new MutationObserver(mutations => { mutations.forEach(mutation => { if (mutation.addedNodes.length) { mutation.addedNodes.forEach(node => { if (node.tagName === 'VIDEO') { node.muted = true; } if (node.querySelectorAll) { const nestedVideos = node.querySelectorAll('video'); nestedVideos.forEach(video => { video.muted = true; }); } }); } }); }); // Start observing the body for added nodes observer.observe(document.body, { childList: true, subtree: true }); });
Editor is loading...
Leave a Comment