Youtube compact sidebar+

Add more buttons in compact sidebar/mini guide

目前為 2024-06-13 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

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