Youtube compact sidebar+

Add more buttons in compact sidebar/mini guide

// ==UserScript==
// @name                   Youtube compact sidebar+
// @name:pt-BR             Youtube barra lateral+
// @namespace              https://greasyfork.org/users/821661
// @match                  https://www.youtube.com/*
// @grant                  GM_xmlhttpRequest
// @grant                  GM_registerMenuCommand
// @grant                  GM_setValue
// @grant                  GM_getValue
// @grant                  GM_addStyle
// @grant                  GM_addStyle
// @run-at                 document-body
// @version                0.4
// @author                 hdyzen
// @description            Add more buttons in compact sidebar/mini guide
// @description:pt-BR      Adiciona mais botões a barra lateral
// @license                GPL-3.0
// ==/UserScript==
'use strict';

// Labels
const labels = {
    home: 'Home',
    shorts: 'Shorts',
    subscriptions: 'Subscriptions',
    you: 'You',
    yourChannel: 'Channel',
    history: 'History',
    playlists: 'Playlists',
    yourVideos: 'Videos',
    watchLater: 'Later',
    liked: 'Liked',
    download: 'Download',
};

// Render commands menu
function renderMenuCommands() {
    Object.entries(labels).forEach(([key, label]) => {
        const state = getStates(key);

        displayItems(key, state);
        GM_registerMenuCommand(`${state ? '✅' : '❌'} ${label}`, e => stateToggle(key, state), { id: key, autoClose: false });
    });
}
renderMenuCommands();

// States toggle
function stateToggle(key, state) {
    const statesNew = getStates();
    statesNew[key] = !state;
    GM_setValue('states', statesNew);
    renderMenuCommands();
}

// Display items
function displayItems(key, state) {
    const body = document.body;

    if (!state) {
        body.classList.add(key);
    } else {
        body.classList.remove(key);
    }
}

// Get states
function getStates(key) {
    const states = GM_getValue('states');
    const statesDefault = {
        home: true,
        shorts: true,
        subscriptions: true,
        you: true,
        yourChannel: true,
        history: true,
        playlists: true,
        yourVideos: true,
        watchLater: true,
        liked: true,
        download: true,
    };

    if (key) return states?.[key] !== undefined ? states[key] : statesDefault[key];
    else return statesDefault;
}

// Patch JSON.parse
const originalParse = JSON.parse;

JSON.parse = function (text) {
    const result = originalParse(text);
    const item = result?.items?.[0]?.guideSectionRenderer?.items?.[3]?.guideCollapsibleSectionEntryRenderer?.sectionItems;

    if (item) {
        item.forEach(item => {
            if (item.guideEntryRenderer) item.guideEntryRenderer.isPrimary = true;
            if (item.guideDownloadsEntryRenderer) item.guideDownloadsEntryRenderer.alwaysShow = true;
        });
    }

    return result;
};

// Styles
GM_addStyle(`
ytd-mini-guide-renderer.ytd-app {
    overflow: auto;

} 
.home ytd-mini-guide-entry-renderer:has(> a[href="/"]) {
    display: none !important;
}
.shorts ytd-mini-guide-entry-renderer:has(> a[title="Shorts"]) {
    display: none !important;
}
.subscriptions ytd-mini-guide-entry-renderer:has(> a[href="/feed/subscriptions"]) {
    display: none !important;
}
.you ytd-mini-guide-entry-renderer:has(> a[href="/feed/you"]) {
    display: none !important;
}
.yourChannel ytd-mini-guide-entry-renderer:has(> a[href^="/channel/"]) {
    display: none !important;
}
.history ytd-mini-guide-entry-renderer:has(> a[href="/feed/history"]) {
    display: none !important;
}
.playlists ytd-mini-guide-entry-renderer:has(> a[href="/feed/playlists"]) {
    display: none !important;
}
.yourVideos ytd-mini-guide-entry-renderer:has(> a[href^="https://studio.youtube.com/"]) {
    display: none !important;
}
.watchLater ytd-mini-guide-entry-renderer:has(> a[href="/playlist?list=WL"]) {
    display: none !important;
}
.liked ytd-mini-guide-entry-renderer:has(> a[href="/playlist?list=LL"]) {
    display: none !important;
}
.download ytd-mini-guide-entry-renderer:has(> a[href="/feed/downloads"]) {
    display: none !important;
}
`);