YOUTUBE: hide low views videos (less than 100k views) (customizable)

hide videos less than 100k views

// ==UserScript==
// @name         YOUTUBE: hide low views videos (less than 100k views) (customizable)
// @namespace    https://github.com/KenKaneki73985
// @license      MIT
// @match        https://www.youtube.com/feed/subscriptions
// @match        https://www.youtube.com
// @description  hide videos less than 100k views 
// @version 0.0.1.20250307132736
// ==/UserScript==
// user_script = "moz-extension://762e4395-b145-4620-8dd9-31bf09e052de/options.html#nav=e203b9b5-3a24-4566-b0e8-3d6bbb72aed0+editor"

(function() {
    'use strict';

    // Function to hide low view videos
    function HIDE_LOW_VIEW_VIDEOS() {
        // Find all elements with the specified class
        const viewsElements = document.querySelectorAll('.inline-metadata-item');
        
        // Filter elements that contain the word "views"
        const viewElements = Array.from(viewsElements).filter(el => el.textContent.includes('views'));

        // Filter for elements with less than 100K views
        const lowViewElements = viewElements.filter(el => {
            // Extract the numeric part
            const viewText = el.textContent.replace(' views', '');
            
            // Check if the element contains 'K'
            if (el.textContent.includes('K')) {
                // Extract the number before 'K'
                const viewCount = parseFloat(viewText.split('K')[0]);
                
                // Return true if views are less than 100
                return viewCount < 100;
                // return viewCount < 500;
            }
            
            // If no 'K', it means less than 1000 views
            // Parse the number directly
            const viewCount = parseInt(viewText.replace(/,/g, ''), 10);
            
            // Return true if views are less than 1000
            return viewCount < 1000;
        });

        // Hide the low view count elements
        if (lowViewElements.length > 0) {
            lowViewElements.forEach(el => {
                // Find the closest ancestor "ytd-rich-item-renderer"
                const videoItem = el.closest('ytd-rich-item-renderer');
                
                // If the video item is found, hide it
                if (videoItem) {
                    videoItem.style.display = 'none';
                }
            });
        }
    }

    // Run on initial page load
    HIDE_LOW_VIEW_VIDEOS();

    // Run on Alt+H key press
    document.addEventListener('keydown', function(event) {
        if (event.altKey && event.key === 'h') {
            HIDE_LOW_VIEW_VIDEOS();
        }
    });

    // Observe scroll and dynamically loaded content
    const observerOptions = {
        childList: true,
        subtree: true
    };

    const observer = new MutationObserver((mutations) => {
        // Check if new videos have been added
        const newVideos = mutations.some(mutation => 
            mutation.type === 'childList' && 
            mutation.addedNodes.length > 0
        );

        if (newVideos) {
            // Small delay to ensure new content is fully rendered
            setTimeout(HIDE_LOW_VIEW_VIDEOS, 100);
        }
    });

    // Start observing the page for changes
    const targetNode = document.body;
    observer.observe(targetNode, observerOptions);
})();

QingJ © 2025

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