🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

Hide Watched YouTube Videos from Recommendations

Hide YouTube videos you've already watched from the recommendations

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

// ==UserScript==
// @name         Hide Watched YouTube Videos from Recommendations
// @namespace    https://tampermonkey.net/
// @version      2.1
// @description  Hide YouTube videos you've already watched from the recommendations
// @author       Nyxia
// @match        *://www.youtube.com/*
// @license      MIT
// @grant        GM_addStyle
// @grant        GM_log
// @grant        GM_openInTab
// ==/UserScript==

(function() {
    'use strict';

    // Function to hide watched videos
    const hideWatchedVideos = () => {
        // Select all video items in the recommendation sections
        const videoItems = document.querySelectorAll('ytd-grid-video-renderer, ytd-compact-video-renderer, ytd-video-renderer');

        videoItems.forEach(video => {
            try {
                // Check if the video has a "watched" label (e.g., 'progress-bar' element indicating it's been watched)
                const progressBar = video.querySelector('.ytd-thumbnail-overlay-resume-playback-renderer');

                // If the video has been partially or fully watched, hide it
                if (progressBar) {
                    video.style.display = 'none';  // Hide the watched video
                    GM_log('Hiding watched video:', video);
                }
            } catch (error) {
                // Log any potential errors for debugging
                console.error('Error hiding watched video:', error);
            }
        });
    };

    // MutationObserver to watch for page updates (e.g., infinite scroll loading more videos)
    const observer = new MutationObserver((mutations) => {
        mutations.forEach((mutation) => {
            hideWatchedVideos();  // Reapply the function every time the page updates
        });
    });

    // Start observing the document for changes in child elements (like new video recommendations)
    observer.observe(document, {
        childList: true,
        subtree: true
    });

    // Initial call to hide videos when the script is first loaded
    hideWatchedVideos();
})();