Created
January 16, 2020 17:02
-
-
Save H-G-Hristov/260a1986d1710ce4f37784c68e3d77c8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function main(){ | |
const durationContainers = Array.from(document.getElementById("items").getElementsByClassName("style-scope ytd-thumbnail-overlay-time-status-renderer")); | |
var durations = durationContainers.map(__span => __span.innerText).map(duration => { | |
if (duration) { | |
return duration.split(":").map(duration => parseInt(duration)).reverse().reduce((acc, e, i) => { | |
return acc + e * Math.pow(60, i); | |
}); | |
} | |
else { | |
return 0; | |
} | |
}); | |
durations = durations.filter(element => 0 !== element); | |
console.log(durations); | |
const totalSeconds = durations.reduce((acc, e, _) => { | |
return acc + e; | |
}); | |
console.log(totalSeconds); | |
const seconds = totalSeconds % 60; | |
const minutes = Math.floor(totalSeconds / 60) % 60; | |
const hours = Math.floor(totalSeconds / 3600); | |
const totalTime = "Play Time: " + hours + ":" + minutes + ":" + seconds; | |
console.log(totalTime); | |
const list = document.getElementById("start-actions"); | |
const div = document.createElement("div"); | |
div.class = "style-scope style-grey-text"; | |
const text = document.createElement("p"); | |
text.innerText = totalTime; | |
div.appendChild(text); | |
list.insertBefore(div, list.childNodes[1]); | |
}; | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment