Hide Community Posts from YouTube Mobile Feed

Hides all Community tab posts (text, polls, images) from the YouTube Mobile homepage feed

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Hide Community Posts from YouTube Mobile Feed
// @namespace    https://greasyfork.org/en/scripts/551101-hide-community-posts-from-youtube-mobile-feed
// @version      1.0
// @description  Hides all Community tab posts (text, polls, images) from the YouTube Mobile homepage feed
// @author       Adam Jensen
// @license MIT
// @match        https://m.youtube.com/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    const TARGET_CLASS = '.rich-section-content';
    const STYLE_ID = 'yt-hide-posts-style'; 

    function addStyle() {
        if (document.getElementById(STYLE_ID)) return;

        const css = `
            ${TARGET_CLASS} {
                display: none !important;
            }
        `;

        const style = document.createElement('style');
        style.id = STYLE_ID;
        style.type = 'text/css';
        style.appendChild(document.createTextNode(css));
        document.head.appendChild(style);
    }

    function observeMutations() {
        const observer = new MutationObserver((mutationsList, observer) => {
            mutationsList.forEach(mutation => {
                if (mutation.type === 'childList') {
                    mutation.addedNodes.forEach(node => {
                        if (node.nodeType === 1 && (node.matches(TARGET_CLASS) || node.querySelector(TARGET_CLASS))) {
                            
                        }
                    });
                }
            });
        });

        setTimeout(() => {
            if (document.body) {
                observer.observe(document.body, { childList: true, subtree: true });
            } 
        }, 100);
    }

    addStyle();
    observeMutations();

})();