var times = [];
document.querySelectorAll('.ytd-thumbnail-overlay-time-status-renderer').forEach(nameElement=> {
nameElement.innerText.trim()?times.push(nameElement.innerText.trim()):null
});
function getElementByXpath(path) {
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}
let video_count = parseInt(getElementByXpath(`//*[@id="stats"]/yt-formatted-string[1]/span[1]`).innerText)
var total_seconds = 0
var total_minutes = 0
for(let i = 0; i<video_count; i++) {
let time_array = times[i].split(':')
total_minutes += parseInt(time_array[0])
total_seconds += parseInt(time_array[1])
}
function formatTime(seconds) {
const h = Math.floor(seconds / 3600);
const m = Math.floor((seconds % 3600) / 60);
const s = Math.round(seconds % 60);
return [
h,
m > 9 ? m : (h ? '0' + m : m || '0'),
s > 9 ? s : '0' + s
].filter(Boolean).join(':');
}
let total_duration = formatTime((total_minutes*60) + total_seconds)
let playlist_title = getElementByXpath(`//*[@id="title"]/yt-formatted-string/a`).innerText
var tpl = 'background-color:greenyellow; border:3px solid orange; font-size:18px; font-weight: bold;padding:3px 5px;color:';
console.log('%c'+playlist_title,
tpl+'red');
console.log(`Total Videos : ${video_count}
Total Duration : ${total_duration}
`)