Forces 6 videos per row, adjusts text sizes, hides checkmarks, adjusts spacing.
当前为
// ==UserScript==
// @name YouTube layout fix
// @namespace http://tampermonkey.net/
// @version 2.28
// @description Forces 6 videos per row, adjusts text sizes, hides checkmarks, adjusts spacing.
// @author Kalakaua
// @match https://www.youtube.com/
// @match https://www.youtube.com/feed/subscriptions*
// @match https://www.youtube.com/feed/playlists*
// @match https://www.youtube.com/channel/*
// @match https://www.youtube.com/@*
// @match https://www.youtube.com/watch*
// @match https://www.youtube.com/results*
// @match https://www.youtube.com/playlist*
// @match https://www.youtube.com/feed/history*
// @grant GM_addStyle
// @run-at document-start
// @license MIT
// ==/UserScript==
(function() {
'use strict';
// --- FINAL ADJUSTABLE VALUES (User Prefs) ---
// === Column Layout ===
const desiredColumnCount = 6; // Number of columns for main content grids
// === Comment Section (Watch Page) ===
const commentTextScale = 1.15;
const commentMetaScale = 1.1;
// === Grid Items - Text Sizes (Home, Subs, Playlists Feed, Channel Videos*) ===
const gridTitleScale = 1.12;
const gridChannelScale = 0.95; // Tuned size
const gridMetadataScale = 0.85; // Tuned size
// === Grid Items - Internal Spacing ===
const gridChannelMarginTop = "-2px";
const gridMetaMarginTop = "-2px";
// === Sidebar (Watch Page Right Sidebar - Compact Video List) ===
const sidebarTitleScale = 1.05;
const sidebarChannelNameScale = 1.0;
const sidebarViewsDateScale = 1.65;
// === Watch Page - Below Video Player ===
const watchOwnerChannelScale = 2.1;
const watchTopRowMarginTop = "-4px";
const watchSubCountMarginTop = "-3.5px";
// === Sidebar Badge Styling (Watch Page Right Sidebar) ===
const sidebarBadgeScale = 0.85;
const sidebarBadgeMarginTop = "2px";
const sidebarBadgeMarginBottom= "0px";
// === Overall Grid Structure ===
const gridEdgePadding = "24px";
const gridItemHorizontalMargin= "6px";
const gridItemBottomMargin = "24px";
// === Sidebar Title Spacing (Watch Page Right Sidebar) ===
const sidebarTitleMarginBottom= "6px";
// --- Technical Values ---
const minimalPxReduction = "0.01px"; // Minimal reduction for calc() robustness
// --- END OF ADJUSTABLE VALUES ---
const css = `
/* --- ADJUST TEXT SIZES (VARIABLES) --- */
:root {
--gm-grid-title-size: ${gridTitleScale}em;
--gm-grid-channel-size: ${gridChannelScale}em;
--gm-grid-metadata-size: ${gridMetadataScale}em;
--gm-comment-text-size: ${commentTextScale}em;
--gm-comment-meta-size: ${commentMetaScale}em;
--gm-sidebar-title-size: ${sidebarTitleScale}em;
--gm-sidebar-channel-size: ${sidebarChannelNameScale}em;
--gm-sidebar-viewsdate-size: ${sidebarViewsDateScale}em;
--gm-sidebar-badge-size: ${sidebarBadgeScale}em;
--gm-watch-owner-channel-size: ${watchOwnerChannelScale}em;
--gm-watch-title-size: 1.5rem;
--gm-search-title-size: 1.0rem;
}
/* ========================================================== */
/* === VARIABLE ITEMS PER ROW - SPECIFIC TARGETING RULES === */
/* ========================================================== */
/* --- Global Container Padding & Width --- */
#contents.ytd-rich-grid-renderer {
padding-left: ${gridEdgePadding} !important; padding-right: ${gridEdgePadding} !important; box-sizing: border-box !important;
width: 100% !important;
}
/* Apply Container padding to Channel pages too (Rule Set 3 active) */
ytd-browse[page-subtype="channels"] #contents.ytd-rich-grid-renderer,
ytd-browse[page-subtype="channels"] ytd-item-section-renderer #contents > ytd-rich-grid-renderer {
padding-left: ${gridEdgePadding} !important; padding-right: ${gridEdgePadding} !important; box-sizing: border-box !important;
width: 100% !important;
}
/* --- Rule Set 2: Playlist Feed Specific Styles (via :not()) --- */
/* Item Width & Margin - Use :not() selector + minimal reduction */
#contents.ytd-rich-grid-renderer ytd-rich-item-renderer:not(
ytd-browse[page-subtype="home"] #contents.ytd-rich-grid-renderer ytd-rich-item-renderer,
ytd-browse[page-subtype="subscriptions"] #contents.ytd-rich-grid-renderer ytd-rich-item-renderer,
/* Exclude Channel items explicitly */
ytd-browse[page-subtype="channels"] #contents.ytd-rich-grid-renderer ytd-grid-video-renderer,
ytd-browse[page-subtype="channels"] ytd-item-section-renderer #contents > ytd-rich-grid-renderer ytd-grid-video-renderer
) {
margin-left: ${gridItemHorizontalMargin} !important; margin-right: ${gridItemHorizontalMargin} !important; margin-bottom: ${gridItemBottomMargin} !important;
max-width: calc(100% / ${desiredColumnCount} - ${gridItemHorizontalMargin} * 2 - ${minimalPxReduction}) !important;
/* overflow: hidden !important; */ /* REMOVED */
}
/* Text/Meta styles for Playlist Feed - Use :not() selector */
#contents.ytd-rich-grid-renderer ytd-rich-item-renderer:not(...) .yt-lockup-metadata-view-model-wiz__title {
font-size: var(--gm-grid-title-size) !important; line-height: 1.2em !important; max-height: 2.4em !important; overflow: hidden !important; text-overflow: ellipsis !important; display: -webkit-box !important; -webkit-line-clamp: 2 !important; -webkit-box-orient: vertical !important; margin-bottom: 1px !important;
}
#contents.ytd-rich-grid-renderer ytd-rich-item-renderer:not(...) .yt-content-metadata-view-model-wiz__metadata-text {
font-size: var(--gm-grid-metadata-size) !important; line-height: 1.3em !important; display: inline !important;
}
#contents.ytd-rich-grid-renderer ytd-rich-item-renderer:not(...) .yt-lockup-metadata-view-model-wiz__metadata {
margin-top: ${gridMetaMarginTop} !important; line-height: 1.3em;
}
#contents.ytd-rich-grid-renderer ytd-rich-item-renderer:not(...) .yt-content-metadata-view-model-wiz__delimiter { /* display: none !important; */ }
#contents.ytd-rich-grid-renderer ytd-rich-item-renderer:not(...) a.yt-core-attributed-string__link--call-to-action-color { font-size: 0.9em !important; margin-top: 2px !important; }
/* --- Rule Set 1: Home & Subscriptions Feed Specific Styles --- */
/* Item Width & Margin (Overrides Rule Set 2, Minimal reduction) */
ytd-browse[page-subtype="home"] #contents.ytd-rich-grid-renderer ytd-rich-item-renderer,
ytd-browse[page-subtype="subscriptions"] #contents.ytd-rich-grid-renderer ytd-rich-item-renderer {
margin-left: ${gridItemHorizontalMargin} !important; margin-right: ${gridItemHorizontalMargin} !important; margin-bottom: ${gridItemBottomMargin} !important;
max-width: calc(100% / ${desiredColumnCount} - ${gridItemHorizontalMargin} * 2 - ${minimalPxReduction}) !important;
/* overflow: hidden !important; */ /* REMOVED */
border: none !important;
}
/* Text/Meta styles for Home/Subs (Specific Selectors, Overrides Rule Set 2) */
ytd-browse[page-subtype="home"] ytd-rich-item-renderer #video-title.ytd-rich-grid-media,
ytd-browse[page-subtype="subscriptions"] ytd-rich-item-renderer #video-title.ytd-rich-grid-media {
font-size: var(--gm-grid-title-size) !important; line-height: 1.2em !important; max-height: 2.4em !important; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; margin-bottom: 1px !important;
}
ytd-browse[page-subtype="home"] ytd-rich-item-renderer #byline-container,
ytd-browse[page-subtype="subscriptions"] ytd-rich-item-renderer #byline-container {
white-space: nowrap !important; overflow: hidden !important; text-overflow: ellipsis !important; display: flex !important; align-items: center !important; margin-top: ${gridChannelMarginTop} !important; line-height: 1.2em !important; gap: 0 !important;
}
ytd-browse[page-subtype="home"] ytd-rich-item-renderer ytd-channel-name,
ytd-browse[page-subtype="subscriptions"] ytd-rich-item-renderer ytd-channel-name {
font-size: var(--gm-grid-channel-size) !important; line-height: 1.25em !important; display: inline-block !important; overflow: hidden !important; text-overflow: ellipsis !important; flex-grow: 1 !important; min-width: 0 !important; margin: 0 !important; padding: 0 !important; vertical-align: baseline !important;
}
ytd-browse[page-subtype="home"] ytd-rich-item-renderer #metadata-line,
ytd-browse[page-subtype="subscriptions"] ytd-rich-item-renderer #metadata-line {
line-height: 1.3em !important; margin-top: ${gridMetaMarginTop} !important; display: block !important; white-space: nowrap !important; overflow: hidden !important; text-overflow: ellipsis !important;
}
ytd-browse[page-subtype="home"] ytd-rich-item-renderer #metadata-line > span,
ytd-browse[page-subtype="subscriptions"] ytd-rich-item-renderer #metadata-line > span {
font-size: var(--gm-grid-metadata-size) !important; line-height: 1.2em !important; display: inline !important; vertical-align: baseline !important;
}
ytd-browse[page-subtype="home"] ytd-rich-item-renderer #metadata-line > span:first-of-type,
ytd-browse[page-subtype="subscriptions"] ytd-rich-item-renderer #metadata-line > span:first-of-type {
margin-right: 0.5em !important;
}
ytd-browse[page-subtype="home"] ytd-rich-item-renderer #metadata-line > span:first-of-type::after,
ytd-browse[page-subtype="subscriptions"] ytd-rich-item-renderer #metadata-line > span:first-of-type::after {
content: none !important;
}
/* --- Rule Set 3: Channel Pages (Videos Tab Grid) --- */
/* *** ACTIVE - Selectors assumed, may need verification *** */
/* Item Width & Margin */
ytd-browse[page-subtype="channels"] #contents.ytd-rich-grid-renderer ytd-grid-video-renderer,
ytd-browse[page-subtype="channels"] ytd-item-section-renderer #contents > ytd-rich-grid-renderer ytd-grid-video-renderer {
margin-left: ${gridItemHorizontalMargin} !important; margin-right: ${gridItemHorizontalMargin} !important; margin-bottom: ${gridItemBottomMargin} !important;
max-width: calc(100% / ${desiredColumnCount} - ${gridItemHorizontalMargin} * 2 - ${minimalPxReduction}) !important;
/* overflow: hidden !important; */ /* REMOVED */
}
/* Text & Meta Styles for Channel Page Video Grid */
ytd-browse[page-subtype="channels"] ytd-grid-video-renderer #video-title {
font-size: var(--gm-grid-title-size) !important; line-height: 1.2em !important; max-height: 2.4em !important; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; margin-bottom: 1px !important;
}
ytd-browse[page-subtype="channels"] ytd-grid-video-renderer #metadata-line {
line-height: 1.3em !important; margin-top: ${gridMetaMarginTop} !important; display: block !important; white-space: nowrap !important; overflow: hidden !important; text-overflow: ellipsis !important;
}
ytd-browse[page-subtype="channels"] ytd-grid-video-renderer #metadata-line > span {
font-size: var(--gm-grid-metadata-size) !important; line-height: 1.2em !important; display: inline !important; vertical-align: baseline !important;
}
ytd-browse[page-subtype="channels"] ytd-grid-video-renderer #metadata-line > span:first-of-type { margin-right: 0.5em !important; }
ytd-browse[page-subtype="channels"] ytd-grid-video-renderer #metadata-line > span:first-of-type::after { content: none !important; }
/* ========================================================== */
/* === HIDE VERIFIED CHECKMARKS (GLOBAL) === */
/* ========================================================== */
ytd-badge-supported-renderer:has(.badge.badge-style-type-verified) { display: none !important; }
/* ========================================================== */
/* === FULLSCREEN FIXES === */
/* ========================================================== */
/* Prevent horizontal scrollbar ONLY when video player is fullscreen */
html.fullscreen,
html.fullscreen body {
overflow-x: hidden !important;
}
/* ========================================================== */
/* === STYLES FOR OTHER AREAS (NOT 6-COLUMN GRID) === */
/* ========================================================== */
/* === WATCH PAGE METADATA (BELOW VIDEO) === */
.title.ytd-video-primary-info-renderer h1.ytd-video-primary-info-renderer { font-size: var(--gm-watch-title-size) !important; line-height: 1.2em !important; }
#top-row.ytd-watch-metadata { margin-top: ${watchTopRowMarginTop} !important; }
ytd-video-owner-renderer ytd-channel-name { font-size: var(--gm-watch-owner-channel-size) !important; line-height: 1.05em !important; margin: 0 !important; padding: 0 !important; display: block !important; }
#owner-sub-count.ytd-video-owner-renderer { margin-top: ${watchSubCountMarginTop} !important; margin-bottom: 0 !important; }
#description-inner #description .content.ytd-video-secondary-info-renderer, .ytd-expander.ytd-video-secondary-info-renderer { font-size: 0.8em !important; line-height: 1.35em !important; }
#info-text.ytd-video-primary-info-renderer { font-size: 0.8em !important; }
/* === SIDEBAR STYLING (Compact Videos - Watch Page Right Sidebar, etc.) === */
ytd-compact-video-renderer h3.ytd-compact-video-renderer { margin-bottom: ${sidebarTitleMarginBottom} !important; margin-top: 0 !important; }
#video-title.ytd-compact-video-renderer { font-size: var(--gm-sidebar-title-size) !important; line-height: 1.3em !important; max-height: 2.6em !important; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
ytd-compact-video-renderer ytd-channel-name { font-size: var(--gm-sidebar-channel-size) !important; line-height: 1.35em !important; margin-bottom: 1px !important; }
ytd-compact-video-renderer #metadata-line span.inline-metadata-item { font-size: var(--gm-sidebar-viewsdate-size) !important; line-height: 1.45em !important; }
ytd-compact-video-renderer ytd-badge-supported-renderer.badges { margin-top: ${sidebarBadgeMarginTop} !important; margin-bottom: ${sidebarBadgeMarginBottom} !important; font-size: var(--gm-sidebar-badge-size) !important; line-height: 1.2 !important; }
/* === SEARCH RESULTS (ytd-video-renderer - List format) === */
ytd-video-renderer { margin-bottom: 16px !important; }
a#video-title.ytd-video-renderer { font-size: var(--gm-search-title-size) !important; margin-bottom: 4px !important; line-height: 1.3em !important; max-height: 2.6em !important; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
#metadata-line.ytd-video-meta-block { font-size: 0.85em !important; line-height: 1.4 !important; }
#channel-name.ytd-video-renderer .ytd-channel-name#text, .ytd-channel-name a { font-size: 0.85em !important; line-height:1.4 !important;}
.metadata-snippet-container.ytd-video-renderer { font-size: 0.85em !important; line-height: 1.4 !important;}
/* === VIDEO PAGE: COMMENT SECTION === */
yt-attributed-string#content-text.ytd-comment-view-model { font-size: var(--gm-comment-text-size) !important; line-height: 1.5em !important; }
#header-author #author-text, .published-time-text.ytd-comment-renderer { font-size: var(--gm-comment-meta-size) !important; }
#toolbar.ytd-comment-action-buttons-renderer { font-size: var(--gm-comment-meta-size) !important; }
#header-author #author-text.ytd-comment-renderer { color: #aaa !important; }
`;
// Inject the CSS using GM_addStyle
if (typeof GM_addStyle === 'function') {
const scriptVersion = (typeof GM_info !== 'undefined' && GM_info.script) ? GM_info.script.version : 'N/A';
GM_addStyle(css);
console.log(`YouTube Layout Script: v${scriptVersion} Active (${desiredColumnCount} Cols) - Added FS Scrollbar Fix`);
} else { /*...*/ }
})();