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

Greasy fork 爱吃馍镜像

Hide Members-Only Videos on Youtube

Hides videos marked "Members-Only" from main landing page.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

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

公众号二维码

扫码关注【爱吃馍】

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

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.

(I already have a user style manager, let me install it!)

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

公众号二维码

扫码关注【爱吃馍】

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

// ==UserScript==
// @name             Hide Members-Only Videos on Youtube
// @namespace        https://greasyfork.org/en/users/4612-gdorn
// @version          1.4
// @description      Hides videos marked "Members-Only" from main landing page.
// @author           GDorn
// @match            https://www.youtube.com/*
// @grant            none
// @license          GPL-3.0
// ==/UserScript==

const ITEM_SELECTOR = 'ytd-rich-item-renderer';

(function() {
    'use strict';

    function hideMembersOnlyElements() {
        document.querySelectorAll(ITEM_SELECTOR).forEach(maybeHide);
    }

    function maybeHide(item) {
        if (item.style.display == 'none') return;
        if (item.textContent.includes('Members only') || item.textContent.includes('Members first')) {
            console.log("Hiding item:", item);
            item.style.display = 'none';
        } else {
            //console.log("Not hiding item:", item);
        }
    }

    function runWhenReady() {
        if (document.readyState === 'complete' || document.readyState === 'interactive') {
            hideMembersOnlyElements();
        } else {
            setTimeout(runWhenReady, 500);
        }
    }

    runWhenReady();

    const observer = new MutationObserver(mutations => {
        for (const { addedNodes } of mutations) {
            for (const node of addedNodes) {
                if (!(node instanceof HTMLElement)) continue;
                if (node.matches(ITEM_SELECTOR)){
                    maybeHide(node);
                }
                else {
                    node.querySelectorAll && node.querySelectorAll(ITEM_SELECTOR).forEach(maybeHide);
                }
            }
        }
    }).observe(document.body, { childList: true, subtree: true });

    window.addEventListener('yt-navigate-finish', hideMembersOnlyElements);

    var oldHref = document.location.href;
    var observer2 = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            if (oldHref != document.location.href) {
                oldHref = document.location.href;
                console.log('location changed!');
                runWhenReady();
                hideMembersOnlyElements();
                setTimeout(hideMembersOnlyElements, 5000); // one last one, just in case things load very slowly

            }
        });
    });


    let attemptCount = 0;
    const maxAttempts = 10;
    const intervalCheck = setInterval(() => {
        if (attemptCount >= maxAttempts) {
            clearInterval(intervalCheck);
            return;
        }
        hideMembersOnlyElements();
        attemptCount++;
    }, 1000);

    hideMembersOnlyElements();
    setTimeout(hideMembersOnlyElements, 5000);  // one last one, just in case things load very slowly
})();