YouTube CSS + Downloader (reload page!)

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

目前為 2023-12-30 提交的版本,檢視 最新版本

  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.  
  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. #top-row.ytd-watch-metadata:not(:hover) .yt-spec-button-shape-next--mono.yt-spec-button-shape-next--tonal {background-color: white !important}
  141. #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}
  142.  
  143. /* padding over video player */
  144. 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}
  145.  
  146. `);
  147.  
  148.  
  149. };
  150.  
  151. //---------------------------------------------------------------------------------------------------------------------------
  152. if (currentURL.startsWith("https://m.youtube.com")) {
  153.  
  154.  
  155. GM_addStyle(`
  156. .downloadbutton:before {content: "Download ⤓" !important}
  157. .downloadbutton {background: white !important; color: gray !important; margin: 5px !important}
  158.  
  159. * {border-radius:0px !important}
  160.  
  161. .pivot-bar-item-title {display:none !important}
  162. ytm-pivot-bar-renderer {height: min-content !important;border:none !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.  
  168.  
  169. /* dark mode above/under videoplayer */
  170. .mobile-topbar-header[data-mode="watch"] {background-color: rgba(0,0,0,1) !important}
  171. .draggable .engagement-panel-section-list-header-wrapper {background-color: black !important;color: white !important}
  172. .engagement-panel-drag-line {background: #fff !important}
  173.  
  174.  
  175.  
  176.  
  177. /* player */
  178. #player-control-overlay.fadein .player-controls-background {background: rgba(0,0,0,.3) !important}
  179. ytm-custom-control .player-controls-top {opacity: .4 !important}
  180. ytm-custom-control .player-controls-middle {opacity: .7 !important}
  181. .time-delimiter {opacity: 0 !important}
  182. ytm-custom-control .player-controls-bottom .icon-button {opacity: 0.8 !important}
  183. #player-control-overlay .player-controls-background-container {visibility: hidden !important}
  184. ytm-custom-control .player-controls-middle .player-control-play-pause-icon.icon-button > c3-icon {height: 46px !important; width: 46px !important}
  185. .progress-bar-playhead-dot {height: 30px !important; border-radius: 50px !important}
  186.  
  187. /* make more space for the video content */
  188. .player-controls-pb {left: 15px !important; right: 15px !important}
  189. ytm-custom-control .player-controls-bottom {left: 0 !important; right: 0 !important}
  190. ytm-custom-control .player-controls-top {top: -8px !important}
  191.  
  192.  
  193. .fullscreen-action-menu {display:none !important}
  194.  
  195. .slim-video-metadata-header .slim-video-information-content.slim-video-information-empty-badge {padding-top: 0 !important}
  196. ytm-slim-video-metadata-section-renderer ytm-slim-owner-renderer {padding-top: 0 !important}
  197. .slim-video-action-bar-actions {padding: 0 0 !important}
  198. .ytm-autonav-bar {display:none !important}
  199. .modern-styling {margin:0 !important}
  200. .draggable .engagement-panel-section-list-header {padding:0 !important}
  201. ytm-engagement-panel-section-list-renderer ytm-comment-simplebox-renderer {display: none !important}
  202. ytm-comment-renderer {padding:0 !important}
  203. ytm-comment-replies-renderer {margin:0 !important}
  204. ytm-single-column-watch-next-results-renderer .single-column-watch-next-modern-panels ytm-comments-entry-point-header-renderer.modern-styling {padding: 0 !important}
  205. ytm-slim-video-metadata-section-renderer ytm-slim-owner-renderer {padding-bottom: 0 !important}
  206. .rich-grid-sticky-header { display: none !important}
  207.  
  208. /* account avatar, search */
  209. .topbar-menu-button-avatar-button, ytm-mobile-topbar-renderer ytm-menu .icon-button {display:block !important;}
  210.  
  211. /* padding uploader avatar and subscribe button */
  212. ytm-slim-video-metadata-section-renderer ytm-slim-owner-renderer {padding: 0 !important}
  213. .slim-owner-profile-icon {margin-right: 2px !important}
  214. /* Title under player */
  215. .slim-video-metadata-header .slim-video-information-content.slim-video-information-empty-badge {padding:0 !important}
  216.  
  217. .mobile-topbar-header-endpoint, .logo-in-player-endpoint {opacity: 0; !important}
  218.  
  219. .ytp-unmute-animated .ytp-unmute-icon {border-bottom: none !important;border-radius: 50px !important;background-color: rgba(255, 255, 255, 0.59) !important}
  220. .ytp-unmute-shrink .ytp-unmute-text {opacity: 0 !important}
  221. .ytp-unmute-shrink .ytp-unmute-box {width: 0 !important}
  222. ytm-reel-shelf-renderer .reel-shelf-header {margin:0 !important}
  223. .chip-bar {display: none !important}
  224.  
  225.  
  226.  
  227. #logo.ytd-masthead:not(:hover) {opacity:0}
  228. #guide-button.ytd-masthead:not(:hover) {opacity:0}
  229. #voice-search-button.ytd-masthead:not(:hover) {opacity:0}
  230. #buttons.ytd-masthead:not(:hover) {opacity:0}
  231. #chips-wrapper.ytd-feed-filter-chip-bar-renderer:not(:hover) {opacity:0}
  232. ytd-comment-simplebox-renderer:not(:hover) {opacity:0}
  233. ytd-mini-guide-entry-renderer[system-icons] .title.ytd-mini-guide-entry-renderer:not(:hover) {opacity:0}
  234. yt-button-shape.ytd-subscribe-button-renderer:not(:hover) {opacity:0.07}
  235.  
  236.  
  237. ytm-comment-thread-renderer {padding:0 !important}
  238. .comment-content {padding: 0 4px !important}
  239.  
  240. /* Feed */
  241. ytm-media-item[use-vertical-layout] .details {margin-top: 0 !important}
  242. ytm-rich-item-renderer ytm-media-item .details {margin-left: 0 !important}
  243. /* Thumbnail Time */
  244. ytm-thumbnail-overlay-time-status-renderer {margin-right: 0 !important}
  245. /* video recommendations under player */
  246. 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}
  247.  
  248. /* Shorts */
  249. ytm-reel-shelf-renderer {border: none !important; margin: 0 !important}
  250. ytm-reel-shelf-renderer .reel-shelf-items > * {margin: 0 !important}
  251.  
  252. /* hide left green border on subscription button */
  253. .yt-spec-button-shape-next--mono.yt-spec-button-shape-next--tonal {background: #f2f2f2 !important}
  254.  
  255.  
  256. `);
  257. }
  258.