Advertisement
alien_fx_fiend

Progress Bar Tweaks /w Chapters Visible

Dec 29th, 2024 (edited)
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 6.57 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. /* Make unplayed progress yellow */
  28. .ytp-progress-bar {
  29.     background-color: yellow !important;
  30. }
  31.  
  32. /* Make sure the hover preview also matches indigo */
  33. .html5-hover-progress, .ytp-hover-progress {
  34.     background-color: indigo !important;
  35. }
  36.  
  37. /* Ensure proper layering */
  38. .html5-progress-list, .ytp-progress-list {
  39.     z-index: 99998 !important;
  40. }
  41.  
  42. /* Make progress bar thicker */
  43. .html5-progress-bar-container, .ytp-progress-bar-container {
  44.     height: 10px !important;
  45. }
  46.  
  47. .html5-progress-bar, .ytp-progress-bar {
  48.     height: 10px !important;
  49. }
  50.  
  51. .html5-progress-list, .ytp-progress-list {
  52.     height: 10px !important;
  53. }
  54.  
  55. .ytp-progress-bar .ytp-play-progress,
  56. .ytp-progress-bar .ytp-load-progress,
  57. .ytp-progress-bar .ytp-hover-progress {
  58.     height: 10px !important;
  59. }
  60.  
  61. /* Update these styles in your JavaScript */
  62. /* Make played progress indigo */
  63. .ytp-progress-bar .ytp-play-progress,
  64. .ytp-progress-bar-container .ytp-play-progress,
  65. .ytp-progress-bar .ytp-play-progress.ytp-swatch-background-color {
  66.     background: indigo !important;
  67.     background-color: indigo !important;
  68. }
  69.  
  70. /* Adjust the scrubber container for the thicker bar */
  71. .html5-scrubber-container, .ytp-scrubber-container {
  72.     height: 10px !important;
  73. }
  74.  
  75. /* When hovering, make it even thicker */
  76. .ytp-progress-bar-container:hover {
  77.     height: 15px !important;
  78. }
  79.  
  80. .ytp-progress-bar-container:hover .ytp-progress-bar,
  81. .ytp-progress-bar-container:hover .ytp-progress-list,
  82. .ytp-progress-bar-container:hover .ytp-play-progress,
  83. .ytp-progress-bar-container:hover .ytp-load-progress,
  84. .ytp-progress-bar-container:hover .ytp-hover-progress {
  85.     height: 15px !important;
  86. }
  87.  
  88. /* Make chapter markers visible */
  89. .ytp-chapter-hover-container {
  90.     display: block !important;
  91.     opacity: 1 !important;
  92. }
  93.  
  94. .ytp-progress-bar .ytp-chapter-marker {
  95.     opacity: 1 !important;
  96.     display: block !important;
  97. }
  98.  
  99. .ytp-progress-bar .ytp-chapter-marker-decoration {
  100.     opacity: 1 !important;
  101.     display: block !important;
  102.     background-color: white !important;
  103.     width: 2px !important;
  104.     height: 100% !important;
  105. }
  106.  
  107. /* Style for chapter titles */
  108. .ytp-chapter-title-content {
  109.     color: white !important;
  110.     background-color: rgba(0, 0, 0, 0.8) !important;
  111.     padding: 2px 4px !important;
  112.     border-radius: 2px !important;
  113.     font-size: 12px !important;
  114. }
  115.  
  116. /* Make sure chapter markers are always visible */
  117. .ytp-progress-bar-container .ytp-progress-bar .ytp-chapter-marker {
  118.     opacity: 1 !important;
  119.     visibility: visible !important;
  120. }
  121.  
  122. /* Enhance chapter marker visibility */
  123. .ytp-progress-bar .ytp-chapter-marker::before {
  124.     content: '';
  125.     position: absolute;
  126.     top: 0;
  127.     width: 2px;
  128.     height: 100%;
  129.     background-color: white !important;
  130.     opacity: 1 !important;
  131. }
  132.  
  133. `;
  134. document.head.appendChild(style);
  135.  
  136. function enforceProgressBarColor() {
  137.     const playProgress = document.querySelector('.ytp-play-progress');
  138.     if (playProgress) {
  139.         playProgress.style.setProperty('background', 'indigo', 'important');
  140.         playProgress.style.setProperty('background-color', 'indigo', 'important');
  141.     }
  142.     if (progressBar) {
  143.         progressBar.style.setProperty('background', 'yellow', 'important');
  144.         progressBar.style.setProperty('background-color', 'yellow', 'important');
  145.     }
  146. }
  147.  
  148. function enforceChapterVisibility() {
  149.     const chapterMarkers = document.querySelectorAll('.ytp-chapter-marker');
  150.     chapterMarkers.forEach(marker => {
  151.         marker.style.setProperty('opacity', '1', 'important');
  152.         marker.style.setProperty('display', 'block', 'important');
  153.     });
  154. }
  155.  
  156. // Function to create or update the notch
  157. function updateNotch() {
  158.     let progressBar = document.querySelector('.ytp-progress-bar');
  159.     let player = document.querySelector('.html5-main-video');
  160.     let progressBarContainer = document.querySelector('.ytp-progress-bar-container');
  161.    
  162.     if (!progressBar || !player || !progressBarContainer) return;
  163.  
  164.     // Create notch if it doesn't exist
  165.     let notch = document.querySelector('.custom-youtube-notch');
  166.     if (!notch) {
  167.         notch = document.createElement('div');
  168.         notch.className = 'custom-youtube-notch';
  169.         progressBarContainer.appendChild(notch);
  170.     }
  171.  
  172.     // Calculate position
  173.     let progress = (player.currentTime / player.duration) * 100;
  174.     let progressBarRect = progressBar.getBoundingClientRect();
  175.     let position = (progressBarRect.width * progress) / 100;
  176.  
  177.     // Update notch position
  178.     notch.style.left = `${position}px`;
  179.     notch.style.top = '50%';
  180.     notch.style.display = 'block';
  181. }
  182.  
  183. // Function to start the interval
  184. function startNotchUpdate() {
  185.     // Initial update
  186.     updateNotch();
  187.     enforceProgressBarColor();
  188.     enforceChapterVisibility();
  189.    
  190.     // Set interval for updates
  191.     // Set interval for updates
  192.     return setInterval(() => {
  193.         updateNotch();
  194.         enforceChapterVisibility();
  195.     }, 1000);
  196.  
  197. // Function to initialize and handle page changes
  198. function initialize() {
  199.     let interval;
  200.  
  201.     // Observer for detecting player load
  202.     const observer = new MutationObserver((mutations) => {
  203.         if (document.querySelector('.html5-main-video')) {
  204.             if (!interval) {
  205.                 interval = startNotchUpdate();
  206.             }
  207.         }
  208.     });
  209.  
  210.     // Start observing
  211.     observer.observe(document.body, {
  212.         childList: true,
  213.         subtree: true
  214.     });
  215.  
  216.     // Handle navigation (for YouTube's SPA nature)
  217.     let lastUrl = location.href;
  218.     new MutationObserver(() => {
  219.         const url = location.href;
  220.         if (url !== lastUrl) {
  221.             lastUrl = url;
  222.             clearInterval(interval);
  223.             interval = startNotchUpdate();
  224.         }
  225.     }).observe(document.body, {subtree: true, childList: true});
  226. }
  227.  
  228. // Start the script
  229. initialize();
  230. /* End JS 23px notch, buffer/ played colors, 10px height */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement