nascent / YouTube - Remove PocketTube Subscription Groups Sidebar Section

// ==UserScript==
// @name         YouTube - Remove PocketTube Subscription Groups Sidebar Section
// @namespace    https://openuserjs.org/users/nascent/
// @version      1.0
// @description  Removes the "Subscription groups" block (added by the PocketTube extension) from the YouTube sidebar.
// @author       nascent
// @match        https://www.youtube.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @copyright    2026, nascent (https://openuserjs.org/users/nascent)
// @license      MIT
// @run-at       document-start
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    const SELECTOR = 'ytd-guide-section-renderer.yms-block-groups';

    const removeBlock = (root = document) => {
        root.querySelectorAll(SELECTOR).forEach(el => {
            // Extra safety: confirm it's the Subscription groups block
            const title = el.querySelector('#guide-section-title');
            if (!title || /Subscription groups/i.test(title.textContent)) {
                el.remove();
            }
        });
    };

    // Initial sweep (in case it's already there)
    removeBlock();

    // Watch for it being (re)inserted
    const observer = new MutationObserver(mutations => {
        for (const m of mutations) {
            for (const node of m.addedNodes) {
                if (node.nodeType !== 1) continue;
                if (node.matches?.(SELECTOR)) {
                    const title = node.querySelector('#guide-section-title');
                    if (!title || /Subscription groups/i.test(title.textContent)) {
                        node.remove();
                        continue;
                    }
                }
                // In case it's nested inside an added subtree
                if (node.querySelector?.(SELECTOR)) {
                    removeBlock(node);
                }
            }
        }
    });

    observer.observe(document.documentElement, {
        childList: true,
        subtree: true,
    });
})();