Better Youtube

Prettier youtube with red sub button and less rounded edges

目前為 2025-06-07 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Better Youtube
// @version     5.2
// @author      tiramifue
// @description Prettier youtube with red sub button and less rounded edges
// @match       https://*.youtube.com/*
// @exclude     *://music.youtube.com/*
// @exclude     *://*.music.youtube.com/*
// @run-at      document-end
// @grant       GM_addStyle
// @grant       GM_registerMenuCommand
// @grant       GM_unregisterMenuCommand
// @grant       GM_getValue
// @grant       GM_setValue
// @namespace   https://greasyfork.org/users/570213
// @license     Apache-2.0
// ==/UserScript==

// updated      2025-06-07

(function(){
    "use strict";

    // ---------- Iframe Handling ----------
    if (window.top !== window.self) {
        switch (location.pathname) {
            case "/live_chat":
                GM_addStyle(getCustomStyleContent("live_chat"));
                break;
        }
        return;
    }


    // ---------- Persistent Settings ----------
    const features = [
        {
            key: "cleanButtonMode",
            name: "Clean Button Mode",
            defaultValue: false,
            onToggle: updateCustomStyleContent
        }
    ]

    class ToggleSystem {
        static getState(key, defaultValue) {
            return GM_getValue(key, defaultValue);
        }

        static setState(key, state) {
            GM_setValue(key, state);
        }

        static registerFeature(feature) {
            const currentState = this.getState(feature.key, feature.defaultValue);
            const stateText = currentState ? "Disable" : "Enable";
            const menuText = `${stateText} ${feature.name}`;

            const menuCommandId = GM_registerMenuCommand(menuText, () => {
                this.toggleFeature(feature);
            });

            feature.menuCommandId = menuCommandId;
        }

        static unregisterFeature(feature) {
            GM_unregisterMenuCommand(feature.menuCommandId);
        }

        static toggleFeature(feature) {
            const currentState = this.getState(feature.key, feature.defaultValue);
            const newState = !currentState;
            this.setState(feature.key, newState);

            this.unregisterFeature(feature);
            this.registerFeature(feature);

            feature.onToggle();
        }

        static initializeAll(features) {
            features.forEach(feature => {
                this.registerFeature(feature);
            })
        }
    }

    ToggleSystem.initializeAll(features);

    // ---------- Clean Button Mode ----------
    function getCleanButtonModeCSS() {
        const state = ToggleSystem.getState("cleanButtonMode", false);
        return state ? `
            .yt-spec-button-shape-next--mono.yt-spec-button-shape-next--tonal, .ytChipShapeInactive, .yt-spec-button-shape-next--overlay.yt-spec-button-shape-next--tonal {
                background: none;
            }
        ` : "";
    }


    // ---------- Theater cinematics ----------
    let isSetup = false;
    let isFullscreen = false;

    // Wait for DOM to be ready
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', init);
    } else {
        init();
    }

    function init() {
        waitForElements();
        document.addEventListener("fullscreenchange", onFullscreenChange);
    }

    function waitForElements() {
        if (isSetup) return;

        const observer = new MutationObserver(function() {
            if (isSetup) return;

            const cinematics = document.querySelector("#cinematics-container");
            const defaultPlayer = document.querySelector("#primary-inner > #player");
            const theaterPlayer = document.querySelector("#full-bleed-container");

            if (cinematics && defaultPlayer && theaterPlayer) {
                isSetup = true;
                observer.disconnect();
                setupTheaterModeWatcher(cinematics, defaultPlayer, theaterPlayer);
            }
        });

        observer.observe(document.body, {
            childList: true,
            subtree: true
        });

        // Check if elements already exist
        const cinematics = document.querySelector("#cinematics-container");
        const defaultPlayer = document.querySelector("#primary-inner > #player");
        const theaterPlayer = document.querySelector("#full-bleed-container");

        if (cinematics && defaultPlayer && theaterPlayer && !isSetup) {
            isSetup = true;
            observer.disconnect();
            setupTheaterModeWatcher(cinematics, defaultPlayer, theaterPlayer);
        }
    }

    function setupTheaterModeWatcher(cinematics, defaultPlayer, theaterPlayer) {
        fixMastheadOpacity();

        const watchFlexy = document.querySelector('ytd-watch-flexy');
        if (!watchFlexy) return;

        const theaterObserver = new MutationObserver(function() {
            const isTheaterMode = watchFlexy.hasAttribute('theater');

            if (isTheaterMode) {
                theaterPlayer.prepend(cinematics);
            } else {
                defaultPlayer.prepend(cinematics);
            }
        });

        theaterObserver.observe(watchFlexy, {
            attributes: true,
            attributeFilter: ['theater']
        });

        if (watchFlexy.hasAttribute('theater')) {
            theaterPlayer.prepend(cinematics);
        }
    }

    function fixMastheadOpacity() {
        const mastheadBg = document.querySelector('#background.style-scope.ytd-masthead');
        if (!mastheadBg) return;

        const observer = new MutationObserver(function(mutations) {
            const isTheaterMode = Boolean(document.querySelector("ytd-watch-flexy[theater]"));
            if (isTheaterMode && !isFullscreen) {
                let opacity = window.scrollY * 0.01;
                if (opacity > 1) opacity = 1;
                mastheadBg.style.setProperty('opacity', opacity);
            }
        });

        observer.observe(mastheadBg, {
            attributes: true,
            attributeFilter: ['style']
        });

        // Set initial state
        const isTheaterMode = document.querySelector("ytd-watch-flexy[theater]");
        if (isTheaterMode) {
            mastheadBg.style.setProperty('opacity', '0');
        }
    }

    function onFullscreenChange() {
        isFullscreen = Boolean(document.fullscreenElement);
        if (!isFullscreen) {
            const mastheadBg = document.querySelector('#background.style-scope.ytd-masthead');
            if (!mastheadBg) return;
            mastheadBg.style.setProperty('opacity', '0');
        }
    }


    // ---------- Styles ----------
    const customStyle = GM_addStyle(getCustomStyleContent());

    function updateCustomStyleContent() {
        customStyle.textContent = getCustomStyleContent();
    }

    function getCustomStyleContent(target = "main") {
        switch (target) {

            case "live_chat":
                return `
html:not(.style-scope)[dark],:not(.style-scope)[dark]{
    --yt-spec-10-percent-layer:rgb(255 255 255 / 10%);
    --yt-spec-badge-chip-background:rgb(255 255 255 / 7%);
    --yt-spec-additive-background:rgb(255 255 255 / 7%);
    --yt-spec-menu-background:rgb(18 18 18 / 98%);
    --yt-live-chat-banner-gradient-scrim: linear-gradient(rgba(18, 18, 18, 0.95), transparent);
    --yt-live-chat-toast-background-color: rgb(18 18 18);
    scrollbar-color: rgb(78 78 78) transparent;
}
yt-live-chat-toast-renderer[is-showing-message] {
    border-top: 1px solid rgb(255 255 255 / 10%);
}
yt-live-chat-banner-renderer {
    backdrop-filter: blur(48px);
    border: 1px solid rgb(255 255 255 / 10%);
    box-shadow: 0px 0px 30px 6px rgba(0, 0, 0, 0.7);
    background: rgb(18 18 18 / 80%);
    --yt-live-chat-primary-text-color: var(--yt-spec-text-primary);
}
tp-yt-iron-dropdown.style-scope.yt-live-chat-app {
    backdrop-filter: blur(48px);
    border: 1px solid rgb(255 255 255 / 10%);
    border-radius: 12px !important;
    box-shadow: 0px 0px 30px 6px rgba(0, 0, 0, 0.7);
    background: rgb(18 18 18 / 80%) !important;
}
ytd-menu-popup-renderer {
    background: transparent;
    backdrop-filter: none;
}
#card.yt-live-chat-viewer-engagement-message-renderer {
    background: transparent;
    border: 1px solid rgb(255 255 255 / 10%);
}
.yt-spec-button-shape-next--mono-inverse.yt-spec-button-shape-next--text {
    color: #f1f1f1;
}
`;

            case "main":
                return `
html:not(.style-scope)[dark],:not(.style-scope)[dark]{
    --yt-spec-10-percent-layer:rgb(255 255 255 / 10%);
    --yt-spec-badge-chip-background:rgb(255 255 255 / 7%);
    --yt-spec-additive-background:rgb(255 255 255 / 7%);
    --yt-spec-menu-background:rgb(18 18 18 / 98%);
    scrollbar-color: rgb(78 78 78) transparent;
}
.YtSearchboxComponentSuggestionsContainer, .ytSearchboxComponentSuggestionsContainer, #ytp-id-18, .ytp-popup, tp-yt-iron-dropdown.style-scope.ytd-popup-container, tp-yt-paper-dialog[modern] {
    backdrop-filter: blur(48px);
    border: 1px solid rgb(255 255 255 / 10%);
    border-radius: 12px !important;
    box-shadow: 0px 0px 30px 6px rgba(0, 0, 0, 0.7);
    background: rgb(18 18 18 / 80%) !important;
}
#background.ytd-masthead {
    backdrop-filter: blur(48px);
    background: rgb(18 18 18 / 80%);
}
ytd-menu-popup-renderer, ytd-multi-page-menu-renderer, ytd-simple-menu-header-renderer, .yt-contextual-sheet-layout-wiz, .yt-sheet-view-model-wiz--contextual {
    background: transparent;
    backdrop-filter: none;
}
ytd-thumbnail a.ytd-thumbnail, ytd-thumbnail:before {
    border-radius: 1px;
}
#thumbnail {
    border-radius: 1px;
}
#subscribe-button-shape button {
    color: var(--yt-spec-text-primary);
    background: #cc0000;
    border-radius: 2px;
    text-transform: uppercase;
}
button.yt-spec-button-shape-next.yt-spec-button-shape-next--filled.yt-spec-button-shape-next--mono.yt-spec-button-shape-next--size-m:hover {
    background: #880000;
}
#sponsor-button button {
    background: var(--yt-spec-badge-chip-background);
    color: var(--yt-spec-text-primary);
}
#sponsor-button button:hover {
    background: #414141;
}
.yt-spec-button-shape-next--size-m {
    border-radius: 2px;
}
.yt-spec-button-shape-next--size-m.yt-spec-button-shape-next--segmented-start {
    border-radius: 2px 0 0 2px;
}
.yt-spec-button-shape-next--size-m.yt-spec-button-shape-next--segmented-end {
    border-radius: 0 2px 2px 0;
}
yt-chip-cloud-chip-renderer[modern-chips][chip-style] {
    border-radius: 2px;
}
#container.ytd-searchbox {
    border-radius: 2px 0 0 2px;
}
#search-icon-legacy.ytd-searchbox {
    border-radius: 0 2px 2px 0;
}
.sbdd_b {
    border-radius: 8px;
}
ytd-watch-metadata[modern-metapanel] #description.ytd-watch-metadata {
    border-radius: 2px;
}
ytd-guide-entry-renderer[guide-refresh] {
    border-radius: 2px;
}
.yt-spec-touch-feedback-shape {
    border-radius: 2px;
}
ytd-rich-metadata-renderer[rounded] {
    border-radius: 2px;
}
.shortsLockupViewModelHostThumbnailContainerRounded {
    border-radius: 2px;
}
#tooltip {
    display: none;
}
ytd-engagement-panel-section-list-renderer[dialog] #content.ytd-engagement-panel-section-list-renderer {
    background: transparent;
}
#header.ytd-engagement-panel-title-header-renderer {
    background: rgb(18 18 18 / 80%);
    border-bottom: 1px solid rgb(255 255 255 / 5%);
}
ytd-engagement-panel-section-list-renderer[dialog] #header.ytd-engagement-panel-section-list-renderer {
    margin: 0;
}
ytd-engagement-panel-section-list-renderer[dialog] ytd-section-list-renderer.ytd-engagement-panel-section-list-renderer {
    background: rgb(18 18 18 / 50%);
}
ytd-engagement-panel-section-list-renderer[dialog][target-id=engagement-panel-comments-section] {
    width: 40vmax;
}
#menu.ytd-engagement-panel-title-header-renderer:not(:empty) {
    flex: 1;
}
#title-container.ytd-engagement-panel-title-header-renderer {
    max-width: 150px;
}
tp-yt-iron-overlay-backdrop.opened {
    opacity: 0.6;
}
ytd-dismissal-follow-up-renderer[darker-dark-theme][dialog][dialog][dialog] {
    background-color: transparent;
}
ytd-guide-entry-renderer[guide-refresh] #endpoint.yt-simple-endpoint.ytd-guide-entry-renderer:hover, ytd-guide-entry-renderer[guide-refresh] #endpoint.yt-simple-endpoint.ytd-guide-entry-renderer:focus {
    border-radius: 2px;
}
ytd-guide-entry-renderer[guide-refresh] #endpoint.yt-simple-endpoint.ytd-guide-entry-renderer:active {
    border-radius: 2px;
}
ytd-guide-entry-renderer[guide-refresh] yt-interaction.ytd-guide-entry-renderer {
    border-radius: 2px;
}
.yt-spec-button-shape-next--size-s {
    border-radius: 2px;
}
button.yt-spec-button-shape-next.yt-spec-button-shape-next--text.yt-spec-button-shape-next--call-to-action.yt-spec-button-shape-next--size-m.yt-spec-button-shape-next--icon-leading.yt-spec-button-shape-next--align-by-text:hover {
    background-color: rgb(38 56 80 / 55%);
}
.yt-spec-button-shape-next--size-l {
    border-radius: 2px;
}
.yt-spec-button-shape-next--size-l.yt-spec-button-shape-next--icon-button {
    width: 44px;
    height: 44px;
}
#content.ytd-engagement-panel-section-list-renderer, ytd-item-section-renderer[static-comments-header] #header.ytd-item-section-renderer, .watch-while-engagement-panel.ytd-reel-video-renderer {
    background: rgb(18 18 18);
}
ytd-reel-video-renderer[is-watch-while-mode] .watch-while-engagement-panel.ytd-reel-video-renderer {
    border-radius: 12px;
}
ytd-item-section-renderer[static-comments-header] #header.ytd-item-section-renderer {
    border-top: 1px solid rgb(255 255 255 / 10%);
}
yt-chip-cloud-chip-renderer, ytd-guide-entry-renderer, #endpoint.yt-simple-endpoint.ytd-guide-entry-renderer:active, #endpoint.yt-simple-endpoint.ytd-guide-entry-renderer:hover, #endpoint.yt-simple-endpoint.ytd-guide-entry-renderer:focus, yt-interaction.ytd-guide-entry-renderer, #description.ytd-watch-metadata, .ytChipShapeChip {
    border-radius: 2px;
}
tp-yt-paper-item.ytd-guide-entry-renderer {
    --paper-item-focused-before-border-radius: 2px;
}
#sponsor-button > ytd-button-renderer {
    background: rgb(35 35 35);
    border-radius: 2px;
}
#sponsor-button > ytd-button-renderer > yt-button-shape > button {
    border: none;
}
#navigation-button-down > ytd-button-renderer > yt-button-shape > button > yt-touch-feedback-shape > div {
    border-radius: 28px;
}
#voice-search-button.ytd-masthead {
    background-color: transparent;
}
yt-interaction.rounded-large .fill.yt-interaction, yt-interaction.rounded-large .stroke.yt-interaction {
    border-radius: 2px;
}
#target[title="Email"] > yt-icon > span > div {
    filter: invert(1);
}
ytd-engagement-panel-section-list-renderer[modern-panels]:not([live-chat-engagement-panel]) {
    border-radius: 2px;
}
ytd-reel-video-renderer:not([enable-player-metadata-container]) .watch-while-engagement-panel.ytd-reel-video-renderer {
    background: rgb(15 15 15);
}
yt-interaction.circular .fill.yt-interaction, yt-interaction.circular .stroke.yt-interaction {
    border-radius: 2px;
}
yt-icon-button.ytd-masthead:hover, ytd-topbar-menu-button-renderer.ytd-masthead:hover, ytd-notification-topbar-button-renderer.ytd-masthead:hover, .ytSearchboxComponentClearButton:hover {
    border-radius: 2px;
}
#overlays > yt-thumbnail-overlay-badge-view-model {
    display: none;
}
ytd-watch-flexy[rounded-player] #ytd-player.ytd-watch-flexy {
    border-radius: 2px;
}
.YtSearchboxComponentInputBox, .ytSearchboxComponentInputBox {
    border-radius: 2px 0 0 2px;
}
.YtSearchboxComponentSearchButton, .ytSearchboxComponentSearchButton {
    border-radius: 0 2px 2px 0;
}
.ytSearchboxComponentClearButton {
    margin-right: 6px;
}
#chip-container.yt-chip-cloud-chip-renderer {
    border-radius: 2px;
}
.ytVideoMetadataCarouselViewModelHost {
    background: var(--yt-spec-badge-chip-background);
    border-radius: 2px;
}
#cinematics-container > #cinematics > div > div {
    transform: scale(1.5, 2) !important;
}
${getCleanButtonModeCSS()}
`;
        }
    }
})();