[Youtube] Compact sidebar with more buttons

Add more buttons in compact sidebar/mini guide

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, Greasemonkey alebo Violentmonkey.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie, ako napríklad Tampermonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, % alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey alebo Userscripts.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie, ako napríklad Tampermonkey.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie správcu používateľských skriptov.

(Už mám správcu používateľských skriptov, nechajte ma ho nainštalovať!)

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

(Už mám správcu používateľských štýlov, nechajte ma ho nainštalovať!)

// ==UserScript==
// @name            [Youtube] Compact sidebar with more buttons
// @namespace       https://greasyfork.org/users/821661
// @version         1.0.2
// @description     Add more buttons in compact sidebar/mini guide
// @author          hdyzen
// @match           https://www.youtube.com/*
// @icon            https://www.google.com/s2/favicons?domain=www.youtube.com/&sz=64
// @grant           GM_registerMenuCommand
// @grant           GM_setValue
// @grant           GM_getValue
// @grant           GM_addStyle
// @license         GPL-3.0-only
// ==/UserScript==

const COMMADS = {
    home: {
        label: "Home",
        state: true,
    },
    shorts: {
        label: "Shorts",
        state: true,
    },
    subscriptions: {
        label: "Subscriptions",
        state: true,
    },
    music: {
        label: "Youtube Music",
        state: true,
    },
    you: {
        label: "You",
        state: true,
    },
    history: {
        label: "History",
        state: true,
    },
    playlists: {
        label: "Playlists",
        state: true,
    },
    yourVideos: {
        label: "Videos",
        state: true,
    },
    yourCourses: {
        label: "Courses",
        state: true,
    },
    watchLater: {
        label: "Later",
        state: true,
    },
    liked: {
        label: "Liked",
        state: true,
    },
    download: {
        label: "Download",
        state: true,
    },
    yourClips: {
        label: "Clips",
        state: true,
    },
};

function renderMenuCommands() {
    for (const key in COMMADS) {
        const state = GM_getValue(key, COMMADS[key].state);
        const label = COMMADS[key].label;

        document.body.classList.toggle(key, !state);

        GM_registerMenuCommand(`${state ? "✅" : "❌"} ${label}`, () => toggleState(key, state), { id: key, autoClose: false });
    }
}
renderMenuCommands();

function toggleState(key, state) {
    COMMADS[key].state = !state;
    GM_setValue(key, COMMADS[key].state);
    renderMenuCommands();
}

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

    if (!items) return result;

    for (const item of items) {
        if (item.guideEntryRenderer) item.guideEntryRenderer.isPrimary = true;
        if (item.guideDownloadsEntryRenderer) item.guideDownloadsEntryRenderer.alwaysShow = true;
    }

    return result;
};

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