NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name Youtube Total Playlist Duration // @namespace benjavr.me // @version 1.1 // @description Shows total playlist duration for youtube playlists. // @author BenjaVR // @include *://www.youtube.com/playlist?list=* // ==/UserScript== (function() { 'use strict'; let container = document.querySelector('.playlist-actions'); let totalTimeSpan = document.createElement('span'); totalTimeSpan.style = 'float:right;'; container.appendChild(totalTimeSpan); function getTimes() { let totalTime = [0, 0, 0]; document.querySelectorAll('.timestamp span').forEach(function(span) { let time = span.innerText; let times = time.split(':'); while (times.length < 3) { times.unshift(0); } for (let i = 0; i < times.length; i++) { times[i] = parseInt(times[i]); totalTime[i] += times[i]; } for (let i = totalTime.length - 1; i >= 0; i--) { if (i !== 0) { while (totalTime[i] > 59) { totalTime[i - 1]++; totalTime[i] -= 60; } } } }); for (let i = 0; i < totalTime.length; i++) { if (i !== 0 && totalTime[i] < 10) { totalTime[i] = '0' + totalTime[i].toString(); } else { totalTime[i] = totalTime[i].toString(); } } let totalTimeString = totalTime.join(':'); totalTimeSpan.innerText = totalTimeString; } getTimes(); window.setInterval(getTimes, 3000); })();