Fix YouTube Watch Flexible Menu Items

To fix YouTube Watch Flexible Menu Items

目前为 2023-10-15 提交的版本,查看 最新版本

  1. /* ==UserStyle==
  2. @name Fix YouTube Watch Flexible Menu Items
  3. @namespace github.com/openstyles/stylus
  4. @version 1.2.0
  5. @description To fix YouTube Watch Flexible Menu Items
  6. @author CY Fung
  7. @license MIT
  8. @preprocessor stylus
  9. @var range menu-flex-width "Menu:Flex:Width" [260, 120, 680, 20, 'px']
  10. @var checkbox hide-menu-icon-text "Hide:Menu:Icon:Text (For:No:Tabview:only)" 1
  11. @var range owner-min-width "Owner:Min:Width (default:disable)" [0, 0, 720, 40, 'px']
  12. @var checkbox margin-fix "Margin Fix" 1
  13. ==/UserStyle== */
  14.  
  15. hideMenuIcon(){
  16.  
  17. @supports (color: var(--hide-menu-icon-text-by-default-v1)) { /* May 2023 */
  18.  
  19. ytd-watch-metadata:not([actions-on-separate-line]) ytd-menu-renderer.ytd-watch-metadata[class] [button-next] .yt-spec-button-shape-next--size-m.yt-spec-button-shape-next--icon-leading .yt-spec-button-shape-next__icon {
  20. margin-right: 0;
  21. margin-left: 0;
  22. contain: layout style;
  23. }
  24.  
  25. ytd-watch-metadata:not([actions-on-separate-line]) ytd-menu-renderer.ytd-watch-metadata[class] [button-next] .yt-spec-button-shape-next--size-m.yt-spec-button-shape-next--icon-leading .yt-spec-button-shape-next__icon+.yt-spec-button-shape-next--button-text-content {
  26. display: none !important;
  27. width: 0 !important;
  28. contain: strict !important;
  29. }
  30.  
  31. /* https://greasyfork.org/en/scripts/456108 */
  32.  
  33. ytd-watch-metadata:not([actions-on-separate-line]) ytd-menu-renderer.ytd-watch-metadata[class] div[name="top_level_translate_btn"] .yt-spec-button-shape-next--size-m.yt-spec-button-shape-next--icon-leading > img:first-child+span:last-child {
  34. display: none !important;
  35. width: 0 !important;
  36. contain: strict !important;
  37. }
  38.  
  39. ytd-watch-metadata:not([actions-on-separate-line]) ytd-menu-renderer.ytd-watch-metadata[class] div[name="top_level_translate_btn"] .yt-spec-button-shape-next--size-m.yt-spec-button-shape-next--icon-leading > img:first-child:nth-last-child(2) {
  40. margin-right: 0 !important;
  41. margin-left: 0 !important;
  42. contain: layout style;
  43. }
  44.  
  45. }
  46.  
  47.  
  48. @supports (color: var(--hide-menu-icon-text-by-default-v2)) { /* Jul 2023 */
  49.  
  50. ytd-watch-metadata:not([actions-on-separate-line]) ytd-menu-renderer.ytd-watch-metadata[class] [button-next] .yt-spec-button-shape-next--size-m.yt-spec-button-shape-next--icon-leading .yt-spec-button-shape-next__icon {
  51. margin-right: 0;
  52. margin-left: 0;
  53. contain: layout style;
  54. }
  55.  
  56. ytd-watch-metadata:not([actions-on-separate-line]) ytd-menu-renderer.ytd-watch-metadata[class] [button-next] .yt-spec-button-shape-next--size-m.yt-spec-button-shape-next--icon-leading .yt-spec-button-shape-next__icon+.yt-spec-button-shape-next__button-text-content {
  57. display: none !important;
  58. width: 0 !important;
  59. contain: strict !important;
  60. }
  61.  
  62. /* https://greasyfork.org/en/scripts/456108 */
  63.  
  64. ytd-watch-metadata:not([actions-on-separate-line]) ytd-menu-renderer.ytd-watch-metadata[class] div[name="top_level_translate_btn"] .yt-spec-button-shape-next--size-m.yt-spec-button-shape-next--icon-leading > img:first-child+span:last-child {
  65. display: none !important;
  66. width: 0 !important;
  67. contain: strict !important;
  68. }
  69.  
  70. ytd-watch-metadata:not([actions-on-separate-line]) ytd-menu-renderer.ytd-watch-metadata[class] div[name="top_level_translate_btn"] .yt-spec-button-shape-next--size-m.yt-spec-button-shape-next--icon-leading > img:first-child:nth-last-child(2) {
  71. margin-right: 0 !important;
  72. margin-left: 0 !important;
  73. contain: layout style;
  74. }
  75.  
  76. }
  77. }
  78.  
  79. generalRules(){
  80. #primary.ytd-watch-flexy #below ytd-video-owner-renderer.style-scope.ytd-watch-metadata,
  81. #primary.ytd-watch-flexy #below #owner {
  82. flex-basis: 90%;
  83. max-width: intrinsic;
  84. max-width: -moz-max-content;
  85. max-width: -webkit-max-content;
  86. max-width: max-content;
  87. }
  88. @supports (color: var(--fix-tooltips-display)) { /* May 2023 */
  89. #actions-inner tp-yt-paper-tooltip {
  90. white-space: nowrap; /* no multline for super chat donation button */
  91. }
  92.  
  93. ytd-watch-flexy #actions-inner.ytd-watch-metadata tp-yt-paper-tooltip{
  94. pointer-events: none !important; /* avoid offset due to cursor */
  95. }
  96. }
  97.  
  98.  
  99. @supports (color: var(--tabview-fix-menu-icons-sizing)){ /* May 2023 */
  100.  
  101. ytd-watch-metadata #actions.item.style-scope.ytd-watch-metadata{
  102. justify-content: end !important;
  103. display:flex;
  104. }
  105. html ytd-watch-metadata[flex-menu-enabled] #actions-inner.ytd-watch-metadata {
  106. /*width: auto !important;*/ /* override 100% */
  107. flex-grow: 1;
  108. }
  109. #sponsor-button.style-scope.ytd-video-owner-renderer {
  110. max-width: calc( ( 100% - 40px ) / 2 );
  111.  
  112. }
  113. #owner:hover #sponsor-button.style-scope.ytd-video-owner-renderer {
  114. max-width: initial;
  115. }
  116.  
  117. #sponsor-button.style-scope.ytd-video-owner-renderer [button-next] {
  118. max-width: 100%;
  119. }
  120.  
  121. #subscribe-button.ytd-watch-metadata {
  122. max-width: calc( ( 100% - 40px ) /3 );
  123. }
  124. #owner:hover #subscribe-button.ytd-watch-metadata {
  125. max-width: initial;
  126. }
  127.  
  128. #subscribe-button.ytd-watch-metadata > ytd-subscribe-button-renderer {
  129. max-width: 100%;
  130. }
  131.  
  132.  
  133. #subscribe-button.ytd-watch-metadata > yt-button-renderer,
  134. #subscribe-button.ytd-watch-metadata > ytd-button-renderer,
  135. #subscribe-button.ytd-watch-metadata > ytd-toggle-button-renderer {
  136. max-width: 100%; /* for Firefox */
  137. }
  138.  
  139.  
  140. #sponsor-button.style-scope.ytd-video-owner-renderer > yt-button-renderer,
  141. #sponsor-button.style-scope.ytd-video-owner-renderer > ytd-button-renderer,
  142. #sponsor-button.style-scope.ytd-video-owner-renderer > ytd-toggle-button-renderer {
  143. max-width: 100%; /* for Firefox */
  144. }
  145.  
  146. }
  147.  
  148.  
  149. @supports (color: var(--fix-youtube-bugs-menu-options-hidden-after-page-updated)) and (contain: var(--size)){ /* May 2023 */
  150. /* added in 2023.05.10 due to new css rule added by YouTube due to the change in darker dark theme implementation stage */
  151.  
  152. /* against YouTube css bug - "max-height: 36px" casue buttons disappear after page changing */
  153. html ytd-menu-renderer[has-flexible-items] {
  154. /* padding-top: 1px; */
  155. max-height: initial; /* limiting the height might prohibit the resizing feature */
  156. /* max-height: 100%; */
  157. /* overflow-y: hidden; */
  158. }
  159.  
  160. ytd-watch-metadata {
  161. --tyt-action-menu-contain: size;
  162. }
  163.  
  164. ytd-watch-metadata[actions-on-separate-line] {
  165. /* actions-on-separate-line is a new attribute introduced in May 2023 Darker Dark Theme. */
  166. --tyt-action-menu-contain: none;
  167.  
  168. }
  169.  
  170. ytd-watch-metadata #owner ~ #actions.item.style-scope.ytd-watch-metadata {
  171. contain: var(--tyt-action-menu-contain); /* follow flex layouting instead of content. content can have larger size */
  172. /* the height will depends on #owner; the width will fill up for flex layout of #top-row */
  173. min-width: var(--menu-min-width, initial) !important;
  174. }
  175.  
  176. ytd-watch-metadata #owner ~ #actions.item.style-scope.ytd-watch-metadata > #actions-inner {
  177. max-height: 100%; /* the y-overflowed items will be shifted such that the first line will be always positiioned at the top */
  178. overflow: hidden; /* for visual only */ /* cannot do "contain: paint" due to tooltips */
  179. }
  180.  
  181. ytd-watch-metadata #owner ~ #actions.item.style-scope.ytd-watch-metadata > #actions-inner ytd-menu-renderer.style-scope.ytd-watch-metadata,
  182. ytd-watch-metadata #owner ~ #actions.item.style-scope.ytd-watch-metadata > #actions-inner .top-level-buttons.ytd-menu-renderer {
  183. row-gap: 12px; /* for visual only */ /* second line will be far below the first line such that it is invisible */
  184. }
  185.  
  186. /* 2023.05.15 */ /* margin-bottom for `.top-level-buttons.ytd-menu-renderer` is not required. */
  187. html ytd-menu-renderer[has-flexible-items][safe-area] .top-level-buttons.ytd-menu-renderer {
  188. margin-bottom: 0; /* override margin-bottom: 4px; */
  189. }
  190.  
  191. }
  192.  
  193. }
  194.  
  195. marginFix(){
  196. @supports (color: var(--fix-single-column-menu-bar-position)){ /* May 2023 */
  197. html ytd-watch-metadata[actions-on-separate-line] #actions.ytd-watch-metadata ytd-menu-renderer.ytd-watch-metadata {
  198. justify-content: flex-end; /* override justify-content: flex-start; */
  199. }
  200. ytd-watch-metadata[actions-on-separate-line] .item.ytd-watch-metadata {
  201. /* override margin-bottom: 12px */
  202. margin-top: 6px;
  203. margin-bottom: 6px;
  204. }
  205. html .item.ytd-watch-metadata {
  206. /* override margin-right: 12px */
  207. /* this is a wrong design to make every .item.ytd-watch-metadata with margin-right. this makes description line becomes not fullwidth */
  208. margin-right: 0px; /* fix description line */
  209. }
  210. #top-row.ytd-watch-metadata {
  211. column-gap: 12px; /* this is the correct way to set gap in flex layout */
  212. }
  213. }
  214.  
  215. @supports (color: var(--tabview-adjust-margin-for-watch-metadata)){ /* May 2023 */
  216. html .item.ytd-watch-metadata {
  217. /* May 2023 theme - no second line in song title */
  218. margin-top: 8px;
  219. }
  220. html #description.ytd-watch-metadata {
  221. font-size: 1.2rem; /* override font-size: 1.4rem; */
  222. line-height: 1.8rem; /* override line-height: 2rem; */
  223. }
  224. }
  225. }
  226.  
  227. @-moz-document domain("youtube.com") {
  228. html{
  229. // --menu-min-width: menu-min-width;
  230. --menu-flex-width: menu-flex-width;
  231. --owner-min-width: owner-min-width;
  232. }
  233.  
  234. ytd-watch-metadata #owner ~ #actions.item.style-scope.ytd-watch-metadata {
  235. flex-basis: var(--menu-flex-width);
  236. min-width: var(--menu-min-width, initial) !important;
  237. }
  238.  
  239. @keyframes ytdMenuRendererAni {
  240.  
  241. 0% {
  242. display: none;
  243. background-position-x: 3px;
  244. }
  245. 100% {
  246. display: flex;
  247. background-position-x: 4px;
  248. animation: none;
  249. }
  250. }
  251.  
  252. ytd-menu-renderer {
  253. animation: ytdMenuRendererAni 1ms linear 0s 1 normal forwards;
  254. }
  255.  
  256. if hide-menu-icon-text {
  257. hideMenuIcon();
  258. }
  259. if owner-min-width > 0px {
  260.  
  261. body #owner.ytd-watch-metadata {
  262. min-width: var(--owner-min-width);
  263. }
  264. }
  265.  
  266. generalRules();
  267. if margin-fix {
  268. marginFix();
  269. }
  270.  
  271. }