YouTube CSS + Downloader (reload page!)

Adds compact CSS style and download button for mobile and desktop site YouTube

目前为 2024-01-12 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name YouTube CSS + Downloader (reload page!)
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.6
  5. // @description Adds compact CSS style and download button for mobile and desktop site YouTube
  6. // @author Agreasyforkuser
  7. // @match https://*.youtube.com/*
  8. // @exclude https://*.youtube.com/tv*
  9. // @icon https://www.google.com/s2/favicons?domain=youtube.com
  10. // @grant GM_addStyle
  11. // ==/UserScript==
  12.  
  13. var currentURL = window.location.href;
  14.  
  15. //////////////////////// Download Button ///////////////////////////////////////
  16.  
  17. 'use strict';
  18. // Function to handle the redirect
  19. function handleRedirect() {
  20. // Get the current YouTube video URL
  21. var currentUrl = window.location.href;
  22. // Extract the video ID from the URL
  23. var videoIdMatch = currentUrl.match(/\/watch\?v=([^&]+)/);
  24. var videoId = videoIdMatch ? videoIdMatch[1] : null;
  25. if (videoId) {
  26. // Redirect to the new URL with "pp" added
  27. var newUrl = 'https://www.youtubepp.com/watch?v=' + videoId;
  28. // Open the new URL in a new tab
  29. window.open(newUrl, '_blank');
  30. }
  31. }
  32. // Function to create and append the "Download" button
  33. function appendDownloadButton() {
  34. // Create the button element
  35. var downloadButton = document.createElement('button');
  36. //downloadButton.innerText = '';
  37. downloadButton.style.margin = '13px'; // Add some margin for better appearance
  38. downloadButton.style.color = 'white';
  39. downloadButton.style.opacity = '0.8';
  40. downloadButton.style.border = 'none';
  41. downloadButton.style.cursor = 'pointer'; // Set the cursor to pointer on hov
  42. downloadButton.addEventListener('click', handleRedirect);
  43. downloadButton.classList.add('downloadbutton');
  44. var existingElementMobile = document.querySelector('.slim-owner-icon-and-title');
  45. var existingElementDesktop = document.querySelector('.ytp-time-display');
  46. if (existingElementMobile) {
  47. existingElementMobile.parentNode.insertBefore(downloadButton, existingElementMobile.nextSibling);
  48. }
  49. if (existingElementDesktop) {
  50. existingElementDesktop.parentNode.insertBefore(downloadButton, existingElementDesktop.nextSibling);
  51. }
  52. }
  53.  
  54. setTimeout(()=>{appendDownloadButton()},2000);
  55.  
  56. //--------------------------------------------------------------------------------------------------------------------------------
  57. if (currentURL.startsWith("https://www.youtube.com")) {
  58.  
  59.  
  60. GM_addStyle(`
  61. * {border-radius:0px !important}
  62.  
  63. .downloadbutton:before {content: "Download 🡇" !important}
  64. .downloadbutton {background-color: black !important; border-radius: 6px !important}
  65.  
  66.  
  67. /* transparent searchbar */
  68. #masthead-container {z-index:0 !important}
  69. /* placeholder text in searchbar */
  70. ::-moz-placeholder {color:transparent !important}
  71. ::-webkit-input-placeholder {color:transparent !important}
  72.  
  73. #search-icon-legacy.ytd-searchbox yt-icon.ytd-searchbox {opacity:0}
  74. #logo.ytd-masthead:not(:hover) {opacity:0}
  75. #guide-button.ytd-masthead:not(:hover) {opacity:0}
  76. #voice-search-button.ytd-masthead:not(:hover) {opacity:0}
  77. #search-icon-legacy.ytd-searchbox:not(:hover) {background-color: transparent !important}
  78. #search-icon-legacy.ytd-searchbox:not(:hover) {border-left:none !important}
  79.  
  80. #buttons.ytd-masthead:not(:hover) {opacity:0}
  81.  
  82. #chips-wrapper.ytd-feed-filter-chip-bar-renderer:not(:hover) {opacity:0}
  83. #container.yt-chip-cloud-renderer:not(:hover) {opacity:0}
  84. yt-chip-cloud-chip-renderer.yt-chip-cloud-renderer {margin-top: 0 !important; margin-bottom: 0 !important}
  85. #contents.ytd-rich-grid-renderer {padding-top:0 !important}
  86.  
  87. ytd-comment-simplebox-renderer:not(:hover) {opacity:0}
  88. ytd-comments-header-renderer {margin: 0 !important}
  89. ytd-mini-guide-entry-renderer[system-icons]:not(:hover) .title.ytd-mini-guide-entry-renderer {opacity:0}
  90.  
  91. .yt-spec-button-shape-next--mono.yt-spec-button-shape-next--outline {display:none}
  92. .yt-spec-button-shape-next--mono.yt-spec-button-shape-next--tonal {background: rgba(0,0,0,.05) !important}
  93.  
  94. /* Channel page transparent upper bar */
  95. #contentContainer.tp-yt-app-header {opacity:0.9}
  96.  
  97. .html5-video-player {width:100%}
  98. .ytp-time-separator {opacity: 0 !important}
  99. .ytp-title {display: none !important}
  100. .ytp-gradient-top {display: none !important}
  101. .ytp-chrome-top-buttons {display: none !important}
  102. .ytp-fullerscreen-edu-chevron {display: none !important}
  103.  
  104.  
  105. /* compact feed */
  106. ytd-rich-item-renderer {margin: 0 !important}
  107. #meta.ytd-rich-grid-media {padding:0 !important}
  108. ytd-compact-video-renderer.ytd-item-section-renderer {margin: 0 !important}
  109. ytd-compact-playlist-renderer.ytd-item-section-renderer {margin: 0 !important}
  110. ytd-compact-video-renderer.ytd-watch-next-secondary-results-renderer:not([expansion="collapsed"]) {margin: 0 !important}
  111.  
  112. /* shorts */
  113. #items.yt-horizontal-list-renderer > .yt-horizontal-list-renderer {padding: 0px !important}
  114. #rich-shelf-header.ytd-rich-shelf-renderer {margin: 0px !important}
  115. #dismissible.ytd-rich-shelf-renderer {margin: 0px !important;border: 0px !important}
  116. /* preview */
  117. .ytp-inline-preview-ui .ytp-inline-preview-controls {top:0 !important;right:0 !important}
  118. /*ytd-thumbnail-overlay-time-status-renderer.ytd-thumbnail {margin: 0 !important}*/
  119. /*#time-status.ytd-thumbnail-overlay-time-status-renderer {color: black !important; background-color: white !important}*/
  120. /*#time-status.ytd-thumbnail-overlay-time-status-renderer {padding-top: 1px;padding-right: 0px;padding-bottom: 0px;padding-left: 1px;}*/
  121.  
  122. /* live chat */
  123. yt-live-chat-viewer-engagement-message-renderer {display: none !important}
  124. ytd-live-chat-frame {border:none !important}
  125.  
  126.  
  127. /* likes seperator */
  128. .yt-spec-button-shape-next--size-m.yt-spec-button-shape-next--segmented-start::after {display:none !important}
  129. /* no button backgrounds until hover */
  130. #top-row.ytd-watch-metadata:not(:hover) .yt-spec-button-shape-next--mono.yt-spec-button-shape-next--tonal {background-color:transparent !important}
  131. #top-row.ytd-watch-metadata:not(:hover) .yt-spec-button-shape-next--mono.yt-spec-button-shape-next--filled {color: black !important; background-color:transparent !important}
  132. /* Info Card */
  133. ytd-info-panel-content-renderer[has-menu] {border: none !important}
  134.  
  135.  
  136. /* survey */
  137. #attached-survey.ytd-rich-grid-media {display: none !important}
  138.  
  139. /* hide left green border on subscription button */
  140. .animated-action__background-container {display: none !important}
  141.  
  142. #top-row.ytd-watch-metadata:not(:hover) .yt-spec-button-shape-next--size-m.yt-spec-button-shape-next--icon-leading-trailing .yt-spec-button-shape-next__secondary-icon {opacity:0}
  143.  
  144. /* padding over video player */
  145. ytd-watch-flexy[default-layout]:not([no-top-margin]):not([reduced-top-margin]) #primary.ytd-watch-flexy, ytd-watch-flexy[default-layout]:not([no-top-margin]):not([reduced-top-margin]) #secondary.ytd-watch-flexy {padding-top:0 !important}
  146.  
  147.  
  148. `);
  149.  
  150.  
  151. };
  152.  
  153. //---------------------------------------------------------------------------------------------------------------------------
  154. if (currentURL.startsWith("https://m.youtube.com")) {
  155.  
  156.  
  157. GM_addStyle(`
  158. .downloadbutton:before {content: "Download ⤓" !important}
  159. .downloadbutton {color: gray !important; margin: 5px !important}
  160.  
  161. ytm-comment-thread-renderer .comment-icon,
  162. .slim-owner-profile-icon,
  163. .channel-thumbnail-icon,
  164. ytm-profile-icon,
  165. .ytm-comments-entry-point-teaser-avatar,
  166. .video-thumbnail-container-compact-rounded,
  167. .collections-stack-wiz__collection-stack1--medium,
  168. ytm-reel-item-renderer.rounded-reel-item .video-thumbnail-container-vertical,
  169. ytm-reel-item-renderer.rounded-reel-item .reel-item-metadata,
  170. .video-thumbnail-container-large.rounded-thumbnail
  171. {border-radius: 0 !important}
  172.  
  173. /* dark mode navbar*/
  174. ytm-pivot-bar-renderer {background-color: transparent !important; background: linear-gradient(180deg, rgba(0,0,0,0) 10%, rgba(0,0,0,0.5032212714187237) 56%, rgba(0,0,0,1) 100%) !important}
  175. ytm-pivot-bar-renderer c3-icon {color: white !important}
  176. .pivot-bar-item-title {display:none !important}
  177. ytm-pivot-bar-renderer {border:none !important}
  178.  
  179. /* dark mode above/under videoplayer */
  180. .mobile-topbar-header[data-mode="watch"] {background-color: rgba(0,0,0,1) !important}
  181. .draggable .engagement-panel-section-list-header-wrapper {background-color: black !important;color: gray !important}
  182. .draggable .engagement-panel-section-list-header {border: none !important}
  183. /* number of comments */
  184. .engagement-panel-section-list-header-context > span:nth-child(1) {color: gray !important}
  185. .engagement-panel-drag-line {opacity:0 !important}
  186. .draggable .engagement-panel-container {border-radius: 0 !important}
  187. ytm-single-column-watch-next-results-renderer .single-column-watch-next-modern-panels ytm-comments-entry-point-header-renderer.modern-styling {border-radius: 0 !important}
  188. ytm-comments-header-renderer ytm-comment-simplebox-renderer {background: linear-gradient(180deg, rgb(0, 0, 0) 0%, rgba(0,0,0,0.5032212714187237) 20%, rgba(0, 0, 0,0) 35%) !important}
  189.  
  190. /* "comments" text */
  191. .comments-entry-point-header-text {display: none !important}
  192.  
  193. /* comments panel close button */
  194. .yt-spec-button-shape-next--mono.yt-spec-button-shape-next--text {color: gray !important}
  195.  
  196.  
  197. /* player */
  198. #player-control-overlay.fadein .player-controls-background {background: rgba(0,0,0,.3) !important}
  199. ytm-custom-control .player-controls-top {opacity: .4 !important}
  200. ytm-custom-control .player-controls-middle {opacity: .7 !important}
  201. .time-delimiter {opacity: 0 !important}
  202. ytm-custom-control .player-controls-bottom .icon-button {opacity: 0.8 !important}
  203. #player-control-overlay .player-controls-background-container {visibility: hidden !important}
  204. ytm-custom-control .player-controls-middle .player-control-play-pause-icon.icon-button > c3-icon {height: 46px !important; width: 46px !important}
  205. .YtProgressBarProgressBarPlayheadDot {height: 30px !important; border-radius: 50px !important}
  206.  
  207. /* player tip scrubber popup */
  208. .tooltip-wrapper {display: none !important}
  209.  
  210. /* make more space for the video content */
  211. .player-controls-pb {left: 15px !important; right: 15px !important}
  212. ytm-custom-control .player-controls-bottom {left: 0 !important; right: 0 !important}
  213. ytm-custom-control .player-controls-top {top: -8px !important}
  214.  
  215.  
  216. .fullscreen-action-menu {display:none !important}
  217.  
  218. .slim-video-metadata-header .slim-video-information-content.slim-video-information-empty-badge {padding-top: 0 !important}
  219. ytm-slim-video-metadata-section-renderer ytm-slim-owner-renderer {padding-top: 0 !important}
  220.  
  221. .modern-styling {margin:0 !important}
  222. ytm-comments-header-renderer {border:none !important}
  223. ytm-comment-renderer {padding:0 !important}
  224. ytm-comment-thread-renderer {padding:0 !important}
  225. .comment-content {padding: 0 4px !important}
  226. ytm-comment-replies-renderer {margin:0 !important}
  227. .comment-simplebox-placeholder {border: none !important}
  228. .comments-simplebox-placeholder {background: none !important}
  229. ytm-single-column-watch-next-results-renderer .single-column-watch-next-modern-panels ytm-comments-entry-point-header-renderer.modern-styling {padding: 0 !important}
  230. ytm-slim-video-metadata-section-renderer ytm-slim-owner-renderer {padding-bottom: 0 !important}
  231. .rich-grid-sticky-header { display: none !important}
  232.  
  233. /* landscape comments panel */
  234. @media (min-width: 931px) and (orientation: landscape) {ytm-engagement-panel {width: 40% !important}}
  235. /* landscape sidebar recommendations */
  236. @media (min-width: 931px) and (orientation: landscape) {ytm-single-column-watch-next-results-renderer [section-identifier="related-items"] {padding:0 !important}}
  237. @media (min-width: 931px) and (orientation: landscape) {ytm-single-column-watch-next-results-renderer [section-identifier="related-items"] .item {padding:0 !important}}
  238.  
  239. /* account avatar, search button, login button */
  240. .topbar-menu-button-avatar-button, ytm-mobile-topbar-renderer ytm-menu .icon-button {display:block !important}
  241. .topbar-menu-button-avatar-button:not(:hover) {opacity: 0.3 !important}
  242. ytm-mobile-topbar-renderer ytm-menu .icon-button:not(:hover) {opacity: 0.3 !important}
  243. .yt-spec-button-shape-next--overlay.yt-spec-button-shape-next--text:not(:hover) {opacity: 0.3 !important}
  244. .mobile-topbar-header-sign-in-button:not(:hover) {opacity: 0.3 !important}
  245.  
  246. /* padding uploader avatar and subscribe button */
  247. ytm-slim-video-metadata-section-renderer ytm-slim-owner-renderer {padding: 0 !important}
  248. .slim-owner-profile-icon {margin-right: 2px !important}
  249. /* Title under player */
  250. .slim-video-metadata-header .slim-video-information-content.slim-video-information-empty-badge {padding:0 !important}
  251.  
  252. .mobile-topbar-header-endpoint:not(:hover), .logo-in-player-endpoint:not(:hover) {opacity: 0 !important}
  253.  
  254. .ytp-unmute-animated .ytp-unmute-icon {border-bottom: none !important;border-radius: 50px !important;background-color: rgba(255, 255, 255, 0.59) !important}
  255. .ytp-unmute-shrink .ytp-unmute-text {opacity: 0 !important}
  256. .ytp-unmute-shrink .ytp-unmute-box {width: 0 !important}
  257. ytm-reel-shelf-renderer .reel-shelf-header {margin:0 !important}
  258. .chip-bar {display: none !important}
  259.  
  260.  
  261.  
  262. #logo.ytd-masthead:not(:hover) {opacity:0}
  263. #guide-button.ytd-masthead:not(:hover) {opacity:0}
  264. #voice-search-button.ytd-masthead:not(:hover) {opacity:0}
  265. #buttons.ytd-masthead:not(:hover) {opacity:0}
  266. #chips-wrapper.ytd-feed-filter-chip-bar-renderer:not(:hover) {opacity:0}
  267. .related-chips-sentinel {display: none !important}
  268. ytd-mini-guide-entry-renderer[system-icons] .title.ytd-mini-guide-entry-renderer:not(:hover) {opacity:0}
  269. yt-button-shape.ytd-subscribe-button-renderer:not(:hover) {opacity:0.07}
  270.  
  271. ytm-item-section-renderer {border: none !important}
  272.  
  273.  
  274.  
  275. /* Feed */
  276. ytm-media-item[use-vertical-layout] .details {margin-top: 0 !important}
  277. ytm-rich-item-renderer ytm-media-item .details {margin-left: 0 !important}
  278. /* Thumbnail Time */
  279. ytm-thumbnail-overlay-time-status-renderer {margin-right: 0 !important}
  280. /* video recommendations under player */
  281. ytm-single-column-watch-next-results-renderer.full-bleed-wn-thumbs [section-identifier="related-items"] ytm-video-with-context-renderer ytm-media-item .details {margin: 0 !important}
  282.  
  283.  
  284.  
  285. /* Shorts */
  286. ytm-reel-shelf-renderer {border: none !important; margin: 0 !important}
  287. ytm-reel-shelf-renderer .reel-shelf-items > * {margin: 0 !important}
  288. .reel-shelf-menu {display: none !important}
  289.  
  290. /* hide left green border on subscription button */
  291. .animated-action__background-container {display: none !important}
  292.  
  293. /* action buttons spacing */
  294. .yt-spec-button-shape-next--mono.yt-spec-button-shape-next--tonal {background: rgba(0,0,0,.05) !important}
  295. .yt-spec-button-shape-next--size-m {padding: 0 6px !important; height: 33px !important}
  296. .slim-video-action-bar-actions > .slim_video_action_bar_renderer_button, .slim-video-action-bar-actions > yt-smartimation, .slim-video-action-bar-actions > ytm-account-link-button-renderer {margin-right: 5px !important}
  297. /* downvotes arent shown anyway */
  298. .yt-spec-button-shape-next--size-m.yt-spec-button-shape-next--icon-button.yt-spec-button-shape-next--segmented-end {width: min-content !important}
  299. .slim-video-action-bar-actions {padding: 3px 3px !important}
  300.  
  301. /* description box */
  302. .draggable ytm-structured-description-content-renderer {padding: 0 !important}
  303. ytm-expandable-video-description-body-renderer.expandable-video-description-modern {margin: 0 !important}
  304. /* description statistics */
  305. ytm-video-description-header-renderer .factoids {padding: 0 !important}
  306.  
  307.  
  308. /* name / views and time / chapter separator */
  309. .ytm-badge-and-byline-separator, .middot {opacity: 0 !important}
  310.  
  311. /* weird empty space after going fullscreen and leaving fullscreen video */
  312. .related-chips-slot-wrapper.slot-open {transform: none !important}
  313.  
  314. `);
  315. }