Untitled

 avatar
user_2795378
plain_text
a month ago
1.3 kB
1
Indexable
Never
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 });
});
Leave a Comment