Remove Channels from WhatsApp Web (Scoped + Safe)

Removes the Channels button from the WhatsApp Web interface, scoped to header only

// ==UserScript==
// @name         Remove Channels from WhatsApp Web (Scoped + Safe)
// @namespace    mailto:[email protected]
// @version      1.3
// @description  Removes the Channels button from the WhatsApp Web interface, scoped to header only
// @author       Mastah Shiki Tohno
// @match        *://web.whatsapp.com/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';
    function removeChannelsButton() {
        const btn = document.querySelector('[aria-label="Channels"]');
        if (btn) {
            const container = btn.closest('div');
            if (container && container.parentNode) {
                container.parentNode.removeChild(container);
                console.log('[Tampermonkey] Channels button removed.');
            }
        }
    }
    function waitForHeaderAndObserve() {
        const headerCheck = setInterval(() => {
            const header = document.querySelector('header');
            if (header) {
                clearInterval(headerCheck);
                removeChannelsButton(); // Initial cleanup

                let isScheduled = false;
                const observer = new MutationObserver(() => {
                    if (!isScheduled) {
                        isScheduled = true;
                        requestAnimationFrame(() => {
                            removeChannelsButton();
                            isScheduled = false;
                        });
                    }
                });
                observer.observe(header, {
                    childList: true,
                    subtree: true
                });
                console.log('[Tampermonkey] MutationObserver started on <header>.');
            }
        }, 500);
    }
    waitForHeaderAndObserve();
})();