Advertisement
alien_fx_fiend

YouTube UserScript ProgressBar Notch + BG Color (Needs Fix for Rightmost Chapter Mark)

Jan 1st, 2025
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 5.47 KB | Source Code | 0 0
  1. /* Start JS 23px notch, buffer/ played colors, 10px height */
  2. // First, inject the CSS
  3. const style = document.createElement('style');
  4. style.textContent = `
  5. .custom-youtube-notch {
  6.     position: absolute;
  7.     width: 23px;
  8.     height: 23px;
  9.     background-color: black;
  10.     border: 2px solid white;
  11.     border-radius: 50%;
  12.     z-index: 999999;
  13.     pointer-events: none;
  14.     transform: translateX(-50%) translateY(-50%);
  15. }
  16.  
  17. /* Make buffered progress hot pink */
  18. .html5-load-progress, .ytp-load-progress {
  19.     background-color: black !important;
  20. }
  21.  
  22. /* Make played progress indigo */
  23. .html5-play-progress, .ytp-play-progress {
  24.     background-color: indigo !important;
  25. }
  26.  
  27. .ytp-chapters-container, .ytp-chapter-hover-container, .ytp-chapters, .ytp-chapter {
  28. z-index: 9999999 !important;
  29. position: relative !important;
  30. left: 0 !important;
  31. height: 100% !important;
  32. border-left: 4px solid black !important;
  33. /*border-left: 4px solid black !important;*/
  34. opacity: 1.0 !important;
  35. }
  36.  
  37. /* Make unplayed progress yellow */
  38. .ytp-progress-bar-container {
  39.     background-color: yellow !important;
  40.     opacity: 0.6 !important;
  41.     /*opacity: 1.0 !important;*/
  42. }
  43.  
  44. /* Make sure the hover preview also matches indigo */
  45. .html5-hover-progress, .ytp-hover-progress {
  46.     background-color: indigo !important;
  47. }
  48.  
  49. /* Ensure proper layering */
  50. .html5-progress-list, .ytp-progress-list {
  51.     z-index: 99998 !important;
  52. }
  53.  
  54. /* Make progress bar thicker */
  55. .html5-progress-bar-container, .ytp-progress-bar-container {
  56.     height: 10px !important;
  57. }
  58.  
  59. .html5-progress-bar, .ytp-progress-bar {
  60.     height: 10px !important;
  61. }
  62.  
  63. .html5-progress-list, .ytp-progress-list {
  64.     height: 10px !important;
  65. }
  66.  
  67. .ytp-progress-bar .ytp-play-progress,
  68. .ytp-progress-bar .ytp-load-progress,
  69. .ytp-progress-bar .ytp-hover-progress {
  70.     height: 10px !important;
  71. }
  72.  
  73. /* Update these styles in your JavaScript */
  74. /* Make played progress indigo */
  75. .ytp-progress-bar .ytp-play-progress,
  76. .ytp-progress-bar-container .ytp-play-progress,
  77. .ytp-progress-bar .ytp-play-progress.ytp-swatch-background-color {
  78.     background: indigo !important;
  79.     background-color: indigo !important;
  80. }
  81.  
  82. /* Adjust the scrubber container for the thicker bar */
  83. .html5-scrubber-container, .ytp-scrubber-container {
  84.     height: 10px !important;
  85. }
  86.  
  87. /* When hovering, make it even thicker */
  88. .ytp-progress-bar-container:hover {
  89.     height: 15px !important;
  90. }
  91.  
  92. .ytp-progress-bar-container:hover .ytp-progress-bar,
  93. .ytp-progress-bar-container:hover .ytp-progress-list,
  94. .ytp-progress-bar-container:hover .ytp-play-progress,
  95. .ytp-progress-bar-container:hover .ytp-load-progress,
  96. .ytp-progress-bar-container:hover .ytp-hover-progress {
  97.     height: 15px !important;
  98. }
  99. `;
  100. document.head.appendChild(style);
  101.  
  102. function enforceProgressBarColor() {
  103.     const playProgress = document.querySelector('.ytp-play-progress');
  104.     if (playProgress) {
  105.         playProgress.style.setProperty('background', 'indigo', 'important');
  106.         playProgress.style.setProperty('background-color', 'indigo', 'important');
  107.     }
  108.     /*if (progressBar) {
  109.          progressBar.style.setProperty('background', 'yellow', 'important');
  110.         progressBar.style.setProperty('background-color', 'yellow', 'important');
  111.  
  112. progressBar.style.setProperty('opacity', '1.0', 'important');
  113.     }*/
  114. }
  115.  
  116. // Function to create or update the notch
  117. function updateNotch() {
  118.     let progressBar = document.querySelector('.ytp-progress-bar');
  119.     let player = document.querySelector('.html5-main-video');
  120.     let progressBarContainer = document.querySelector('.ytp-progress-bar-container');
  121.    
  122.     if (!progressBar || !player || !progressBarContainer) return;
  123.  
  124.     // Create notch if it doesn't exist
  125.     let notch = document.querySelector('.custom-youtube-notch');
  126.     if (!notch) {
  127.         notch = document.createElement('div');
  128.         notch.className = 'custom-youtube-notch';
  129.         progressBarContainer.appendChild(notch);
  130.     }
  131.  
  132.     // Calculate position
  133.     let progress = (player.currentTime / player.duration) * 100;
  134.     let progressBarRect = progressBar.getBoundingClientRect();
  135.     let position = (progressBarRect.width * progress) / 100;
  136.  
  137.     // Update notch position
  138.     notch.style.left = `${position}px`;
  139.     notch.style.top = '50%';
  140.     notch.style.display = 'block';
  141. }
  142.  
  143. // Function to start the interval
  144. function startNotchUpdate() {
  145.     // Initial update
  146.     updateNotch();
  147.     //enforceProgressBarColor();
  148.    
  149.     // Set interval for updates
  150.     return setInterval(updateNotch, 1000);
  151. }
  152.  
  153. // Function to initialize and handle page changes
  154. function initialize() {
  155.     let interval;
  156.  
  157.     // Observer for detecting player load
  158.     const observer = new MutationObserver((mutations) => {
  159.         if (document.querySelector('.html5-main-video')) {
  160.             if (!interval) {
  161.                 interval = startNotchUpdate();
  162.             }
  163.         }
  164.     });
  165.  
  166.     // Start observing
  167.     observer.observe(document.body, {
  168.         childList: true,
  169.         subtree: true
  170.     });
  171.  
  172.     // Handle navigation (for YouTube's SPA nature)
  173.     let lastUrl = location.href;
  174.     new MutationObserver(() => {
  175.         const url = location.href;
  176.         if (url !== lastUrl) {
  177.             lastUrl = url;
  178.             clearInterval(interval);
  179.             interval = startNotchUpdate();
  180.         }
  181.     }).observe(document.body, {subtree: true, childList: true});
  182. }
  183.  
  184. // Start the script
  185. initialize();
  186. /* End JS 23px notch, buffer/ played colors, 10px height */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement