Better Youtube

Prettier youtube with red sub button and less rounded edges

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

您需要先安裝使用者腳本管理器擴展,如 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     7
// @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-15

(function(){
    "use strict";

    const isBlackModeScript = false;

    // ---------- 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
        },
        {
            key: "animatedPopups",
            name: "Animated Popups",
            defaultValue: true,
            onToggle: updateCustomStyleContent
        },
        {
            key: "blackMode",
            name: "Black Mode",
            defaultValue: isBlackModeScript,
            onToggle: () => {
                updateCinematicsBackground();
                updateCustomStyleContent();
            }
        }
    ]

    class ToggleSystem {
        static getState(key) {
            const feature = features.find(f => f.key === key);
            const defaultValue = feature.defaultValue;
            return GM_getValue(key, defaultValue);
        }

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

        static registerFeature(feature) {
            const currentState = this.getState(feature.key);
            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);
            const newState = !currentState;
            this.setState(feature.key, newState);

            this.unregisterAll(features);
            this.registerAll(features);

            feature.onToggle();
        }

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

        static unregisterAll(features) {
            features.forEach(feature => {
                this.unregisterFeature(feature);
            })
        }
    }

    ToggleSystem.registerAll(features);


    // ---------- Black Mode cinematics ----------
    const fillRectOriginal = CanvasRenderingContext2D.prototype.fillRect;

    function updateCinematicsBackground() {
        const defaultCinematicsBackground = "#0f0f0f";
        const blackModeCinematicsBackground = "#000";

        if (ToggleSystem.getState("blackMode")) {
            CanvasRenderingContext2D.prototype.fillRect = function(x, y, w, h) {
                if (typeof this.fillStyle === "string" && this.fillStyle === defaultCinematicsBackground) {
                    this.fillStyle = blackModeCinematicsBackground;
                }
                return fillRectOriginal.call(this, x, y, w, h);
            }
        } else {
            CanvasRenderingContext2D.prototype.fillRect = fillRectOriginal;
        }
    }

    updateCinematicsBackground();


    // ---------- 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") {
        const bm = ToggleSystem.getState("blackMode");
        const rgbBg = bm ? "0 0 0" : "15 15 15";
        const scrollbarRgbColor = bm ? "60 60 60" : "78 78 78";
        const bgVariables = bm ? `
--yt-spec-brand-background-solid: #000;
--yt-spec-brand-background-primary: #000;
--yt-spec-brand-background-secondary: #000;
--yt-spec-general-background-a: #000;
--yt-spec-base-background: #000;
` : "";

        switch (target) {

            case "live_chat":
                return `
html:not(.style-scope)[dark],:not(.style-scope)[dark]{
    --custom-bg-98: rgb(${rgbBg} / 98%);
    --custom-bg-80: rgb(${rgbBg} / 80%);

    ${bgVariables}

    --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: var(--custom-bg-98);
    --yt-live-chat-banner-gradient-scrim: linear-gradient(rgb(${rgbBg} / 95%), transparent);
    --yt-live-chat-toast-background-color: rgb(${rgbBg});
    scrollbar-color: rgb(${scrollbarRgbColor}) 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: var(--custom-bg-98);
    --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: var(--custom-bg-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]{
    --custom-bg-98: rgb(${rgbBg} / 98%);
    --custom-bg-80: rgb(${rgbBg} / 80%);
    --custom-bg-50: rgb(${rgbBg} / 50%);
    --custom-base-bg: rgb(${rgbBg});

    ${bgVariables}

    --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: var(--custom-bg-98);
    scrollbar-color: rgb(${scrollbarRgbColor}) transparent;
    --yt-frosted-glass-desktop: var(--custom-bg-80);
}

${bm ? `
html[dark] {
    background: #000 !important;
}
` : ""}

.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: var(--custom-bg-80) !important;
}
#background.ytd-masthead {
    backdrop-filter: blur(48px);
    background: var(--custom-bg-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;
}
#subscribe-button-shape button:hover {
    background: #880000;
}
#sponsor-button button {
    background: var(--yt-spec-badge-chip-background);
    color: var(--yt-spec-text-primary);
}
#sponsor-button button:hover {
    background: ${bm ? "#333333" : "#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: var(--custom-bg-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: var(--custom-bg-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: var(--custom-base-bg);
}
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(${bm ? "18 18 18" : "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;
}
ytd-live-chat-frame[round-background] #show-hide-button.ytd-live-chat-frame>ytd-toggle-button-renderer.ytd-live-chat-frame, ytd-live-chat-frame[round-background] #show-hide-button.ytd-live-chat-frame>ytd-button-renderer.ytd-live-chat-frame {
    border-radius: 2px;
}


${ToggleSystem.getState("animatedPopups") ? `
/* 1) iPhone-style popup animation */
@keyframes popupAnimation {
  0%   { opacity: 0; transform: scale(0.9); }
  70%  { opacity: 1; transform: scale(1.02); }
  100% { transform: scale(1); }
}

@keyframes popupAnimationUp {
  0% { opacity: 0; transform: scale(0.9) translateY(25px); }
  60% { opacity: 1; transform: scale(1.02) translateY(-5px); }
  100% { transform: scale(1) translateY(0); }
}

tp-yt-iron-dropdown.ytd-popup-container {
  transform-origin: top center !important;
  animation: popupAnimation 300ms cubic-bezier(0.25,0.1,0.25,1) both !important;
  overflow: visible !important; /* never scroll the wrapper */
}

/* 2) Remove YouTube’s inline size caps so menus fit exactly */
tp-yt-iron-dropdown.ytd-popup-container
  yt-sheet-view-model,
tp-yt-iron-dropdown.ytd-popup-container
  ytd-menu-popup-renderer,
tp-yt-iron-dropdown.ytd-popup-container
  ytd-multi-page-menu-renderer {
  max-width: none !important;
  max-height: none !important;
  overflow: visible !important;
}

/* 3) If content actually overflows, allow only vertical scrolling */
tp-yt-iron-dropdown.ytd-popup-container
  ytd-menu-popup-renderer,
tp-yt-iron-dropdown.ytd-popup-container
  ytd-multi-page-menu-renderer {
  overflow-x: hidden !important;
  overflow-y: auto   !important;
  /* optional: cap height so huge menus don’t fill the whole screen */
  /* max-height: 80vh !important; */
}

/* popup animation for search suggestions */
div.ytSearchboxComponentSuggestionsContainer[role="listbox"] {
  transform-origin: top center !important;
  animation: popupAnimation 300ms cubic-bezier(0.25, 0.1, 0.25, 1) both !important;
}

/* — apply animation to the gear/settings menu */
div.ytp-popup.ytp-settings-menu {
  transform-origin: bottom center !important;
  animation: popupAnimationUp 300ms cubic-bezier(0.25,0.1,0.25,1) both !important;
  overflow-x: hidden !important;
  overflow-y: auto   !important;
}
` : ""}


${ToggleSystem.getState("cleanButtonMode") ? `
.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;
}
` : ""}


`;
        }
    }
})();