Prevent autoplayed featured videos on YouTube channel profiles

Prevent autoplayed featured videos on YouTube channel profile pages

目前为 2024-09-16 提交的版本。查看 最新版本

// ==UserScript==
// @name         Prevent autoplayed featured videos on YouTube channel profiles
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Prevent autoplayed featured videos on YouTube channel profile pages
// @author       aspen138
// @match        https://www.youtube.com/@*/featured
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Function to pause the video
    function pauseVideo() {
        const video = document.querySelector('video');
        if (video && !video.paused) {
            video.pause();
            console.log('YouTube autoplay video paused.');
        }
    }

    // Create a MutationObserver to monitor for video elements
    const observer = new MutationObserver((mutations) => {
        pauseVideo();
    });

    // Start observing the document body for changes
    observer.observe(document.body, { childList: true, subtree: true });

    // Attempt to pause the video immediately in case it's already there
    pauseVideo();

})();