YouTube layout fix

Forces 6 videos per row, adjusts text sizes, hides checkmarks, adjusts spacing.

目前为 2025-04-15 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name YouTube layout fix
  3. // @namespace http://tampermonkey.net/
  4. // @version 2.28
  5. // @description Forces 6 videos per row, adjusts text sizes, hides checkmarks, adjusts spacing.
  6. // @author Kalakaua
  7. // @match https://www.youtube.com/
  8. // @match https://www.youtube.com/feed/subscriptions*
  9. // @match https://www.youtube.com/feed/playlists*
  10. // @match https://www.youtube.com/channel/*
  11. // @match https://www.youtube.com/@*
  12. // @match https://www.youtube.com/watch*
  13. // @match https://www.youtube.com/results*
  14. // @match https://www.youtube.com/playlist*
  15. // @match https://www.youtube.com/feed/history*
  16. // @grant GM_addStyle
  17. // @run-at document-start
  18. // @license MIT
  19. // ==/UserScript==
  20.  
  21. (function() {
  22. 'use strict';
  23.  
  24. // --- FINAL ADJUSTABLE VALUES (User Prefs) ---
  25.  
  26. // === Column Layout ===
  27. const desiredColumnCount = 6; // Number of columns for main content grids
  28.  
  29. // === Comment Section (Watch Page) ===
  30. const commentTextScale = 1.15;
  31. const commentMetaScale = 1.1;
  32.  
  33. // === Grid Items - Text Sizes (Home, Subs, Playlists Feed, Channel Videos*) ===
  34. const gridTitleScale = 1.12;
  35. const gridChannelScale = 0.95; // Tuned size
  36. const gridMetadataScale = 0.85; // Tuned size
  37.  
  38. // === Grid Items - Internal Spacing ===
  39. const gridChannelMarginTop = "-2px";
  40. const gridMetaMarginTop = "-2px";
  41.  
  42. // === Sidebar (Watch Page Right Sidebar - Compact Video List) ===
  43. const sidebarTitleScale = 1.05;
  44. const sidebarChannelNameScale = 1.0;
  45. const sidebarViewsDateScale = 1.65;
  46.  
  47. // === Watch Page - Below Video Player ===
  48. const watchOwnerChannelScale = 2.1;
  49. const watchTopRowMarginTop = "-4px";
  50. const watchSubCountMarginTop = "-3.5px";
  51.  
  52. // === Sidebar Badge Styling (Watch Page Right Sidebar) ===
  53. const sidebarBadgeScale = 0.85;
  54. const sidebarBadgeMarginTop = "2px";
  55. const sidebarBadgeMarginBottom= "0px";
  56.  
  57. // === Overall Grid Structure ===
  58. const gridEdgePadding = "24px";
  59. const gridItemHorizontalMargin= "6px";
  60. const gridItemBottomMargin = "24px";
  61.  
  62. // === Sidebar Title Spacing (Watch Page Right Sidebar) ===
  63. const sidebarTitleMarginBottom= "6px";
  64.  
  65. // --- Technical Values ---
  66. const minimalPxReduction = "0.01px"; // Minimal reduction for calc() robustness
  67.  
  68. // --- END OF ADJUSTABLE VALUES ---
  69.  
  70.  
  71. const css = `
  72. /* --- ADJUST TEXT SIZES (VARIABLES) --- */
  73. :root {
  74. --gm-grid-title-size: ${gridTitleScale}em;
  75. --gm-grid-channel-size: ${gridChannelScale}em;
  76. --gm-grid-metadata-size: ${gridMetadataScale}em;
  77. --gm-comment-text-size: ${commentTextScale}em;
  78. --gm-comment-meta-size: ${commentMetaScale}em;
  79. --gm-sidebar-title-size: ${sidebarTitleScale}em;
  80. --gm-sidebar-channel-size: ${sidebarChannelNameScale}em;
  81. --gm-sidebar-viewsdate-size: ${sidebarViewsDateScale}em;
  82. --gm-sidebar-badge-size: ${sidebarBadgeScale}em;
  83. --gm-watch-owner-channel-size: ${watchOwnerChannelScale}em;
  84. --gm-watch-title-size: 1.5rem;
  85. --gm-search-title-size: 1.0rem;
  86. }
  87.  
  88.  
  89. /* ========================================================== */
  90. /* === VARIABLE ITEMS PER ROW - SPECIFIC TARGETING RULES === */
  91. /* ========================================================== */
  92.  
  93. /* --- Global Container Padding & Width --- */
  94. #contents.ytd-rich-grid-renderer {
  95. padding-left: ${gridEdgePadding} !important; padding-right: ${gridEdgePadding} !important; box-sizing: border-box !important;
  96. width: 100% !important;
  97. }
  98. /* Apply Container padding to Channel pages too (Rule Set 3 active) */
  99. ytd-browse[page-subtype="channels"] #contents.ytd-rich-grid-renderer,
  100. ytd-browse[page-subtype="channels"] ytd-item-section-renderer #contents > ytd-rich-grid-renderer {
  101. padding-left: ${gridEdgePadding} !important; padding-right: ${gridEdgePadding} !important; box-sizing: border-box !important;
  102. width: 100% !important;
  103. }
  104.  
  105.  
  106. /* --- Rule Set 2: Playlist Feed Specific Styles (via :not()) --- */
  107. /* Item Width & Margin - Use :not() selector + minimal reduction */
  108. #contents.ytd-rich-grid-renderer ytd-rich-item-renderer:not(
  109. ytd-browse[page-subtype="home"] #contents.ytd-rich-grid-renderer ytd-rich-item-renderer,
  110. ytd-browse[page-subtype="subscriptions"] #contents.ytd-rich-grid-renderer ytd-rich-item-renderer,
  111. /* Exclude Channel items explicitly */
  112. ytd-browse[page-subtype="channels"] #contents.ytd-rich-grid-renderer ytd-grid-video-renderer,
  113. ytd-browse[page-subtype="channels"] ytd-item-section-renderer #contents > ytd-rich-grid-renderer ytd-grid-video-renderer
  114. ) {
  115. margin-left: ${gridItemHorizontalMargin} !important; margin-right: ${gridItemHorizontalMargin} !important; margin-bottom: ${gridItemBottomMargin} !important;
  116. max-width: calc(100% / ${desiredColumnCount} - ${gridItemHorizontalMargin} * 2 - ${minimalPxReduction}) !important;
  117. /* overflow: hidden !important; */ /* REMOVED */
  118. }
  119. /* Text/Meta styles for Playlist Feed - Use :not() selector */
  120. #contents.ytd-rich-grid-renderer ytd-rich-item-renderer:not(...) .yt-lockup-metadata-view-model-wiz__title {
  121. 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;
  122. }
  123. #contents.ytd-rich-grid-renderer ytd-rich-item-renderer:not(...) .yt-content-metadata-view-model-wiz__metadata-text {
  124. font-size: var(--gm-grid-metadata-size) !important; line-height: 1.3em !important; display: inline !important;
  125. }
  126. #contents.ytd-rich-grid-renderer ytd-rich-item-renderer:not(...) .yt-lockup-metadata-view-model-wiz__metadata {
  127. margin-top: ${gridMetaMarginTop} !important; line-height: 1.3em;
  128. }
  129. #contents.ytd-rich-grid-renderer ytd-rich-item-renderer:not(...) .yt-content-metadata-view-model-wiz__delimiter { /* display: none !important; */ }
  130. #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; }
  131.  
  132.  
  133. /* --- Rule Set 1: Home & Subscriptions Feed Specific Styles --- */
  134. /* Item Width & Margin (Overrides Rule Set 2, Minimal reduction) */
  135. ytd-browse[page-subtype="home"] #contents.ytd-rich-grid-renderer ytd-rich-item-renderer,
  136. ytd-browse[page-subtype="subscriptions"] #contents.ytd-rich-grid-renderer ytd-rich-item-renderer {
  137. margin-left: ${gridItemHorizontalMargin} !important; margin-right: ${gridItemHorizontalMargin} !important; margin-bottom: ${gridItemBottomMargin} !important;
  138. max-width: calc(100% / ${desiredColumnCount} - ${gridItemHorizontalMargin} * 2 - ${minimalPxReduction}) !important;
  139. /* overflow: hidden !important; */ /* REMOVED */
  140. border: none !important;
  141. }
  142. /* Text/Meta styles for Home/Subs (Specific Selectors, Overrides Rule Set 2) */
  143. ytd-browse[page-subtype="home"] ytd-rich-item-renderer #video-title.ytd-rich-grid-media,
  144. ytd-browse[page-subtype="subscriptions"] ytd-rich-item-renderer #video-title.ytd-rich-grid-media {
  145. 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;
  146. }
  147. ytd-browse[page-subtype="home"] ytd-rich-item-renderer #byline-container,
  148. ytd-browse[page-subtype="subscriptions"] ytd-rich-item-renderer #byline-container {
  149. 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;
  150. }
  151. ytd-browse[page-subtype="home"] ytd-rich-item-renderer ytd-channel-name,
  152. ytd-browse[page-subtype="subscriptions"] ytd-rich-item-renderer ytd-channel-name {
  153. 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;
  154. }
  155. ytd-browse[page-subtype="home"] ytd-rich-item-renderer #metadata-line,
  156. ytd-browse[page-subtype="subscriptions"] ytd-rich-item-renderer #metadata-line {
  157. line-height: 1.3em !important; margin-top: ${gridMetaMarginTop} !important; display: block !important; white-space: nowrap !important; overflow: hidden !important; text-overflow: ellipsis !important;
  158. }
  159. ytd-browse[page-subtype="home"] ytd-rich-item-renderer #metadata-line > span,
  160. ytd-browse[page-subtype="subscriptions"] ytd-rich-item-renderer #metadata-line > span {
  161. font-size: var(--gm-grid-metadata-size) !important; line-height: 1.2em !important; display: inline !important; vertical-align: baseline !important;
  162. }
  163. ytd-browse[page-subtype="home"] ytd-rich-item-renderer #metadata-line > span:first-of-type,
  164. ytd-browse[page-subtype="subscriptions"] ytd-rich-item-renderer #metadata-line > span:first-of-type {
  165. margin-right: 0.5em !important;
  166. }
  167. ytd-browse[page-subtype="home"] ytd-rich-item-renderer #metadata-line > span:first-of-type::after,
  168. ytd-browse[page-subtype="subscriptions"] ytd-rich-item-renderer #metadata-line > span:first-of-type::after {
  169. content: none !important;
  170. }
  171.  
  172.  
  173. /* --- Rule Set 3: Channel Pages (Videos Tab Grid) --- */
  174. /* *** ACTIVE - Selectors assumed, may need verification *** */
  175. /* Item Width & Margin */
  176. ytd-browse[page-subtype="channels"] #contents.ytd-rich-grid-renderer ytd-grid-video-renderer,
  177. ytd-browse[page-subtype="channels"] ytd-item-section-renderer #contents > ytd-rich-grid-renderer ytd-grid-video-renderer {
  178. margin-left: ${gridItemHorizontalMargin} !important; margin-right: ${gridItemHorizontalMargin} !important; margin-bottom: ${gridItemBottomMargin} !important;
  179. max-width: calc(100% / ${desiredColumnCount} - ${gridItemHorizontalMargin} * 2 - ${minimalPxReduction}) !important;
  180. /* overflow: hidden !important; */ /* REMOVED */
  181. }
  182. /* Text & Meta Styles for Channel Page Video Grid */
  183. ytd-browse[page-subtype="channels"] ytd-grid-video-renderer #video-title {
  184. 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;
  185. }
  186. ytd-browse[page-subtype="channels"] ytd-grid-video-renderer #metadata-line {
  187. line-height: 1.3em !important; margin-top: ${gridMetaMarginTop} !important; display: block !important; white-space: nowrap !important; overflow: hidden !important; text-overflow: ellipsis !important;
  188. }
  189. ytd-browse[page-subtype="channels"] ytd-grid-video-renderer #metadata-line > span {
  190. font-size: var(--gm-grid-metadata-size) !important; line-height: 1.2em !important; display: inline !important; vertical-align: baseline !important;
  191. }
  192. ytd-browse[page-subtype="channels"] ytd-grid-video-renderer #metadata-line > span:first-of-type { margin-right: 0.5em !important; }
  193. ytd-browse[page-subtype="channels"] ytd-grid-video-renderer #metadata-line > span:first-of-type::after { content: none !important; }
  194.  
  195.  
  196. /* ========================================================== */
  197. /* === HIDE VERIFIED CHECKMARKS (GLOBAL) === */
  198. /* ========================================================== */
  199. ytd-badge-supported-renderer:has(.badge.badge-style-type-verified) { display: none !important; }
  200.  
  201.  
  202. /* ========================================================== */
  203. /* === FULLSCREEN FIXES === */
  204. /* ========================================================== */
  205. /* Prevent horizontal scrollbar ONLY when video player is fullscreen */
  206. html.fullscreen,
  207. html.fullscreen body {
  208. overflow-x: hidden !important;
  209. }
  210.  
  211.  
  212. /* ========================================================== */
  213. /* === STYLES FOR OTHER AREAS (NOT 6-COLUMN GRID) === */
  214. /* ========================================================== */
  215. /* === WATCH PAGE METADATA (BELOW VIDEO) === */
  216. .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; }
  217. #top-row.ytd-watch-metadata { margin-top: ${watchTopRowMarginTop} !important; }
  218. 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; }
  219. #owner-sub-count.ytd-video-owner-renderer { margin-top: ${watchSubCountMarginTop} !important; margin-bottom: 0 !important; }
  220. #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; }
  221. #info-text.ytd-video-primary-info-renderer { font-size: 0.8em !important; }
  222.  
  223. /* === SIDEBAR STYLING (Compact Videos - Watch Page Right Sidebar, etc.) === */
  224. ytd-compact-video-renderer h3.ytd-compact-video-renderer { margin-bottom: ${sidebarTitleMarginBottom} !important; margin-top: 0 !important; }
  225. #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; }
  226. ytd-compact-video-renderer ytd-channel-name { font-size: var(--gm-sidebar-channel-size) !important; line-height: 1.35em !important; margin-bottom: 1px !important; }
  227. ytd-compact-video-renderer #metadata-line span.inline-metadata-item { font-size: var(--gm-sidebar-viewsdate-size) !important; line-height: 1.45em !important; }
  228. 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; }
  229.  
  230. /* === SEARCH RESULTS (ytd-video-renderer - List format) === */
  231. ytd-video-renderer { margin-bottom: 16px !important; }
  232. 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; }
  233. #metadata-line.ytd-video-meta-block { font-size: 0.85em !important; line-height: 1.4 !important; }
  234. #channel-name.ytd-video-renderer .ytd-channel-name#text, .ytd-channel-name a { font-size: 0.85em !important; line-height:1.4 !important;}
  235. .metadata-snippet-container.ytd-video-renderer { font-size: 0.85em !important; line-height: 1.4 !important;}
  236.  
  237. /* === VIDEO PAGE: COMMENT SECTION === */
  238. yt-attributed-string#content-text.ytd-comment-view-model { font-size: var(--gm-comment-text-size) !important; line-height: 1.5em !important; }
  239. #header-author #author-text, .published-time-text.ytd-comment-renderer { font-size: var(--gm-comment-meta-size) !important; }
  240. #toolbar.ytd-comment-action-buttons-renderer { font-size: var(--gm-comment-meta-size) !important; }
  241. #header-author #author-text.ytd-comment-renderer { color: #aaa !important; }
  242.  
  243. `;
  244.  
  245. // Inject the CSS using GM_addStyle
  246. if (typeof GM_addStyle === 'function') {
  247. const scriptVersion = (typeof GM_info !== 'undefined' && GM_info.script) ? GM_info.script.version : 'N/A';
  248. GM_addStyle(css);
  249. console.log(`YouTube Layout Script: v${scriptVersion} Active (${desiredColumnCount} Cols) - Added FS Scrollbar Fix`);
  250. } else { /*...*/ }
  251.  
  252. })();