YouTube CSS + Downloader (reload page!)

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

目前為 2024-01-09 提交的版本,檢視 最新版本

  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.backgroundColor = 'black';
  40. downloadButton.style.opacity = '0.8';
  41. downloadButton.style.border = 'none';
  42. downloadButton.style.cursor = 'pointer'; // Set the cursor to pointer on hov
  43. downloadButton.addEventListener('click', handleRedirect);
  44. downloadButton.classList.add('downloadbutton');
  45. var existingElementMobile = document.querySelector('.slim-owner-bylines');
  46. var existingElementDesktop = document.querySelector('.ytp-time-display');
  47. if (existingElementMobile) {
  48. existingElementMobile.parentNode.insertBefore(downloadButton, existingElementMobile.nextSibling);
  49. }
  50. if (existingElementDesktop) {
  51. existingElementDesktop.parentNode.insertBefore(downloadButton, existingElementDesktop.nextSibling);
  52. }
  53. }
  54.  
  55. setTimeout(()=>{appendDownloadButton()},1500);
  56.  
  57. //--------------------------------------------------------------------------------------------------------------------------------
  58. if (currentURL.startsWith("https://www.youtube.com")) {
  59.  
  60.  
  61. GM_addStyle(`
  62. * {border-radius:0px !important}
  63.  
  64. .downloadbutton:before {content: "Download 🡇" !important}
  65. .downloadbutton {border-radius: 6px !important}
  66.  
  67.  
  68. /* transparent searchbar */
  69. #masthead-container {z-index:0 !important}
  70. /* placeholder text in searchbar */
  71. ::-moz-placeholder {color:transparent !important}
  72. ::-webkit-input-placeholder {color:transparent !important}
  73.  
  74. #search-icon-legacy.ytd-searchbox yt-icon.ytd-searchbox {opacity:0}
  75. #logo.ytd-masthead:not(:hover) {opacity:0}
  76. #guide-button.ytd-masthead:not(:hover) {opacity:0}
  77. #voice-search-button.ytd-masthead:not(:hover) {opacity:0}
  78. #search-icon-legacy.ytd-searchbox:not(:hover) {background-color: transparent !important}
  79. #search-icon-legacy.ytd-searchbox:not(:hover) {border-left:none !important}
  80.  
  81. #buttons.ytd-masthead:not(:hover) {opacity:0}
  82.  
  83. #chips-wrapper.ytd-feed-filter-chip-bar-renderer:not(:hover) {opacity:0}
  84. #container.yt-chip-cloud-renderer:not(:hover) {opacity:0}
  85. yt-chip-cloud-chip-renderer.yt-chip-cloud-renderer {margin-top: 0 !important; margin-bottom: 0 !important}
  86. #contents.ytd-rich-grid-renderer {padding-top:0 !important}
  87.  
  88. ytd-comment-simplebox-renderer:not(:hover) {opacity:0}
  89. ytd-comments-header-renderer {margin: 0 !important}
  90. ytd-mini-guide-entry-renderer[system-icons]:not(:hover) .title.ytd-mini-guide-entry-renderer {opacity:0}
  91.  
  92. .yt-spec-button-shape-next--mono.yt-spec-button-shape-next--outline {display:none}
  93. .yt-spec-button-shape-next--mono.yt-spec-button-shape-next--tonal {background: rgba(0,0,0,.05) !important}
  94.  
  95. /* Channel page transparent upper bar */
  96. #contentContainer.tp-yt-app-header {opacity:0.9}
  97.  
  98. .html5-video-player {width:100%}
  99. .ytp-time-separator {opacity: 0 !important}
  100. .ytp-title {display: none !important}
  101. .ytp-gradient-top {display: none !important}
  102. .ytp-chrome-top-buttons {display: none !important}
  103. .ytp-fullerscreen-edu-chevron {display: none !important}
  104.  
  105.  
  106. /* compact feed */
  107. ytd-rich-item-renderer {margin: 0 !important}
  108. #meta.ytd-rich-grid-media {padding:0 !important}
  109. ytd-compact-video-renderer.ytd-item-section-renderer {margin: 0 !important}
  110. ytd-compact-playlist-renderer.ytd-item-section-renderer {margin: 0 !important}
  111. ytd-compact-video-renderer.ytd-watch-next-secondary-results-renderer:not([expansion="collapsed"]) {margin: 0 !important}
  112.  
  113. /* shorts */
  114. #items.yt-horizontal-list-renderer > .yt-horizontal-list-renderer {padding: 0px !important}
  115. #rich-shelf-header.ytd-rich-shelf-renderer {margin: 0px !important}
  116. #dismissible.ytd-rich-shelf-renderer {margin: 0px !important;border: 0px !important}
  117. /* preview */
  118. .ytp-inline-preview-ui .ytp-inline-preview-controls {top:0 !important;right:0 !important}
  119. /*ytd-thumbnail-overlay-time-status-renderer.ytd-thumbnail {margin: 0 !important}*/
  120. /*#time-status.ytd-thumbnail-overlay-time-status-renderer {color: black !important; background-color: white !important}*/
  121. /*#time-status.ytd-thumbnail-overlay-time-status-renderer {padding-top: 1px;padding-right: 0px;padding-bottom: 0px;padding-left: 1px;}*/
  122.  
  123. /* live chat */
  124. yt-live-chat-viewer-engagement-message-renderer {display: none !important}
  125. ytd-live-chat-frame {border:none !important}
  126.  
  127.  
  128. /* likes seperator */
  129. .yt-spec-button-shape-next--size-m.yt-spec-button-shape-next--segmented-start::after {display:none !important}
  130. /* no button backgrounds until hover */
  131. #top-row.ytd-watch-metadata:not(:hover) .yt-spec-button-shape-next--mono.yt-spec-button-shape-next--tonal {background-color:transparent !important}
  132. #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}
  133. /* Info Card */
  134. ytd-info-panel-content-renderer[has-menu] {border: none !important}
  135.  
  136.  
  137. /* survey */
  138. #attached-survey.ytd-rich-grid-media {display: none !important}
  139.  
  140. /* hide left green border on subscription button */
  141. .animated-action__background-container {display: none !important}
  142.  
  143. #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}
  144.  
  145. /* padding over video player */
  146. 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}
  147.  
  148.  
  149. `);
  150.  
  151.  
  152. };
  153.  
  154. //---------------------------------------------------------------------------------------------------------------------------
  155. if (currentURL.startsWith("https://m.youtube.com")) {
  156.  
  157.  
  158. GM_addStyle(`
  159. .downloadbutton:before {content: "Download ⤓" !important}
  160. .downloadbutton {background: white !important; color: gray !important; margin: 5px !important}
  161.  
  162. * {border-radius:0px !important}
  163.  
  164. /* dark mode navbar*/
  165. ytm-pivot-bar-renderer {background: rgba(0,0,0,1) !important;}
  166. ytm-pivot-bar-renderer c3-icon {color: rgba(255,255,255,1) !important}
  167. .pivot-bar-item-title {display:none !important}
  168. ytm-pivot-bar-renderer {border:none !important}
  169.  
  170. /* dark mode above/under videoplayer */
  171. .mobile-topbar-header[data-mode="watch"] {background-color: rgba(0,0,0,1) !important}
  172. .draggable .engagement-panel-section-list-header-wrapper {background-color: black !important;color: white !important}
  173. /* number of comments */
  174. .engagement-panel-section-list-header-context > span:nth-child(1) {color: white !important}
  175. .engagement-panel-drag-line {background: #fff !important}
  176.  
  177. /* comments panel close button */
  178. .yt-spec-button-shape-next--mono.yt-spec-button-shape-next--text {color: gray !important}
  179.  
  180.  
  181. /* player */
  182. #player-control-overlay.fadein .player-controls-background {background: rgba(0,0,0,.3) !important}
  183. ytm-custom-control .player-controls-top {opacity: .4 !important}
  184. ytm-custom-control .player-controls-middle {opacity: .7 !important}
  185. .time-delimiter {opacity: 0 !important}
  186. ytm-custom-control .player-controls-bottom .icon-button {opacity: 0.8 !important}
  187. #player-control-overlay .player-controls-background-container {visibility: hidden !important}
  188. ytm-custom-control .player-controls-middle .player-control-play-pause-icon.icon-button > c3-icon {height: 46px !important; width: 46px !important}
  189. .YtProgressBarProgressBarPlayheadDot {height: 30px !important; border-radius: 50px !important}
  190.  
  191. /* player tip scrubber popup */
  192. .tooltip-wrapper {display: none !important}
  193.  
  194. /* make more space for the video content */
  195. .player-controls-pb {left: 15px !important; right: 15px !important}
  196. ytm-custom-control .player-controls-bottom {left: 0 !important; right: 0 !important}
  197. ytm-custom-control .player-controls-top {top: -8px !important}
  198.  
  199.  
  200. .fullscreen-action-menu {display:none !important}
  201.  
  202. .slim-video-metadata-header .slim-video-information-content.slim-video-information-empty-badge {padding-top: 0 !important}
  203. ytm-slim-video-metadata-section-renderer ytm-slim-owner-renderer {padding-top: 0 !important}
  204. .slim-video-action-bar-actions {padding: 0 0 !important}
  205. .ytm-autonav-bar {display:none !important}
  206. .modern-styling {margin:0 !important}
  207. .draggable .engagement-panel-section-list-header {padding:0 !important; border: none !important}
  208. ytm-comments-header-renderer {border:none !important}
  209. ytm-engagement-panel-section-list-renderer ytm-comment-simplebox-renderer {display: none !important}
  210. ytm-comment-renderer {padding:0 !important}
  211. ytm-comment-replies-renderer {margin:0 !important}
  212. ytm-single-column-watch-next-results-renderer .single-column-watch-next-modern-panels ytm-comments-entry-point-header-renderer.modern-styling {padding: 0 !important}
  213. ytm-slim-video-metadata-section-renderer ytm-slim-owner-renderer {padding-bottom: 0 !important}
  214. .rich-grid-sticky-header { display: none !important}
  215.  
  216. /* landscape comments panel */
  217. @media (min-width: 931px) and (orientation: landscape) {ytm-engagement-panel {width: 40% !important}}
  218. /* landscape sidebar recommendations */
  219. @media (min-width: 931px) and (orientation: landscape) {ytm-single-column-watch-next-results-renderer [section-identifier="related-items"] {padding:0 !important}}
  220. @media (min-width: 931px) and (orientation: landscape) {ytm-single-column-watch-next-results-renderer [section-identifier="related-items"] .item {padding:0 !important}}
  221.  
  222. /* account avatar, search */
  223. .topbar-menu-button-avatar-button, ytm-mobile-topbar-renderer ytm-menu .icon-button {display:block !important;}
  224. .mobile-topbar-header-sign-in-button:not(:hover) {opacity:.3}
  225.  
  226. /* padding uploader avatar and subscribe button */
  227. ytm-slim-video-metadata-section-renderer ytm-slim-owner-renderer {padding: 0 !important}
  228. .slim-owner-profile-icon {margin-right: 2px !important}
  229. /* Title under player */
  230. .slim-video-metadata-header .slim-video-information-content.slim-video-information-empty-badge {padding:0 !important}
  231.  
  232. .mobile-topbar-header-endpoint:not(:hover), .logo-in-player-endpoint:not(:hover) {opacity: 0 !important}
  233.  
  234. .ytp-unmute-animated .ytp-unmute-icon {border-bottom: none !important;border-radius: 50px !important;background-color: rgba(255, 255, 255, 0.59) !important}
  235. .ytp-unmute-shrink .ytp-unmute-text {opacity: 0 !important}
  236. .ytp-unmute-shrink .ytp-unmute-box {width: 0 !important}
  237. ytm-reel-shelf-renderer .reel-shelf-header {margin:0 !important}
  238. .chip-bar {display: none !important}
  239.  
  240.  
  241.  
  242. #logo.ytd-masthead:not(:hover) {opacity:0}
  243. #guide-button.ytd-masthead:not(:hover) {opacity:0}
  244. #voice-search-button.ytd-masthead:not(:hover) {opacity:0}
  245. #buttons.ytd-masthead:not(:hover) {opacity:0}
  246. #chips-wrapper.ytd-feed-filter-chip-bar-renderer:not(:hover) {opacity:0}
  247. ytd-comment-simplebox-renderer:not(:hover) {opacity:0}
  248. ytd-mini-guide-entry-renderer[system-icons] .title.ytd-mini-guide-entry-renderer:not(:hover) {opacity:0}
  249. yt-button-shape.ytd-subscribe-button-renderer:not(:hover) {opacity:0.07}
  250.  
  251.  
  252. ytm-comment-thread-renderer {padding:0 !important}
  253. .comment-content {padding: 0 4px !important}
  254.  
  255. /* Feed */
  256. ytm-media-item[use-vertical-layout] .details {margin-top: 0 !important}
  257. ytm-rich-item-renderer ytm-media-item .details {margin-left: 0 !important}
  258. /* Thumbnail Time */
  259. ytm-thumbnail-overlay-time-status-renderer {margin-right: 0 !important}
  260. /* video recommendations under player */
  261. 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}
  262.  
  263. /* Shorts */
  264. ytm-reel-shelf-renderer {border: none !important; margin: 0 !important}
  265. ytm-reel-shelf-renderer .reel-shelf-items > * {margin: 0 !important}
  266.  
  267. /* hide left green border on subscription button */
  268. .animated-action__background-container {display: none !important}
  269.  
  270. /* action buttons spacing */
  271. .yt-spec-button-shape-next--mono.yt-spec-button-shape-next--tonal {background: rgba(0,0,0,.05) !important}
  272. .yt-spec-button-shape-next--size-m {padding: 0 6px !important; height: 32px !important}
  273.  
  274. /* description box */
  275. .draggable ytm-structured-description-content-renderer {padding: 0 !important}
  276.  
  277. /* name / views separator */
  278. .ytm-badge-and-byline-separator {opacity: 0 !important}
  279.  
  280.  
  281. `);
  282. }
  283.