YouTube Playlist Time Length

Adds the overall playlist length.

  1. // ==UserScript==
  2. // @name YouTube Playlist Time Length
  3. // @namespace https://violentmonkey.github.io/
  4. // @version 1.0.0
  5. // @description Adds the overall playlist length.
  6. // @description Adapted from script https://greasyfork.org/en/scripts/439291-youtube-playlist-length
  7. // @author André Augusto
  8. // @match *://www.youtube.com/playlist?list=*
  9. // @grant none
  10. // @require https://code.jquery.com/jquery-2.2.4.min.js
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. document.onreadystatechange = function () {
  16. if (document.readyState === 'complete') {
  17. setTimeout(function() {
  18. function convertS(sec) {var hrs = Math.floor(sec / 3600); var min = Math.floor((sec - (hrs * 3600)) / 60); var seconds = sec - (hrs * 3600) - (min * 60); seconds = Math.round(seconds * 100) / 100;var result = (hrs < 10 ? "0" + hrs : hrs) + ':'; result += (min < 10 ? "0" + min : min) + ":"; result += (seconds < 10 ? "0" + seconds : seconds); return result; }; var ytp = document.querySelectorAll("ytd-playlist-video-list-renderer > #contents > ytd-playlist-video-renderer");var time = 0; for (var i = 0; i < ytp.length; i++) {var a = ytp[i].getElementsByTagName('ytd-thumbnail-overlay-time-status-renderer')[0].innerText;var tx = a.split(':'); if (tx.length < 3) {time = time + Number(tx[0]) * 60 + Number(tx[1]);} else if (tx.length = 3) {time = time + Number(tx[0]) * 60 * 60 + Number(tx[1]) * 60 + Number(tx[2]);}}; var ytpT = convertS(time);
  19. time=document.createElement('span');
  20. time.innerText=ytpT;
  21. time.className='testing';
  22. time.style='color:#AAAAAA; font-family:"Roboto","Arial",sans-serif; font-size:1.4rem; line-height:2rem;';
  23.  
  24. const stats = document.getElementById('stats');
  25. stats.appendChild(time);
  26. let timestyle = document.createElement('style');
  27. timestyle.innerText='.testing::before {content: "•"; margin: 0 4px}'
  28. time.appendChild(timestyle);
  29. }, 2000)
  30. }
  31. }
  32. })();