Prevent autoplayed featured videos on YouTube channel profile pages

Prevent autoplayed featured videos on YouTube channel profile pages.

目前為 2024-11-19 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Prevent autoplayed featured videos on YouTube channel profile pages
// @namespace    http://tampermonkey.net/
// @version      1.3
// @description  Prevent autoplayed featured videos on YouTube channel profile pages.
// @author       aspen138
// @match        https://www.youtube.com/@*/featured
// @match        https://www.youtube.com/@*
// @match        https://www.youtube.com/*
// @exclude      https://www.youtube.com/watch?v=*
// @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.');
        }
    }

    // Function to bold and highlight the specified element and its children
    function highlightElement() {
        const element = document.querySelector('.page-header-view-model-wiz__page-header-content-metadata');
        if (element) {
            element.style.backgroundColor = 'yellow'; // Highlight with yellow background

            // Bold and mimic the style for each child
            Array.from(element.children).forEach(child => {
                child.style.fontWeight = 'bold'; // Make each child bold
                child.style.color = 'red'; // Set font color to red
                child.style.textDecoration = 'none'; // Remove any text decoration if needed
            });

            // Also, bold and mimic styles for any spans inside the children
            const spans = element.querySelectorAll('span');
            spans.forEach(span => {
                span.style.fontWeight = 'bold';
                span.style.color = 'red'; // Set font color to red
                span.style.textDecoration = 'none'; // Remove any text decoration
            });

            console.log('Element and its children highlighted and bolded with red font color.');
        }
    }

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

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

    // Attempt to pause the video and highlight the element immediately in case they're already there
    pauseVideo();
    highlightElement();

    // Counter for setInterval executions
    let executionCount = 0;

    // Use setInterval to repeatedly check for the element and apply styles
    const intervalId = setInterval(() => {
        highlightElement();
        executionCount++;

        // Clear the interval after two executions
        if (executionCount >= 2) {
            clearInterval(intervalId);
        }
    }, 1000); // Check every 1000 milliseconds (1 second)
})();




QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址