[Youtube] Compact sidebar with more buttons

Add more buttons in compact sidebar/mini guide

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==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;
}
`);