Last active
March 11, 2019 23:40
-
-
Save TristanWiley/4c839cf3c42550dd8ffb3685f01c0caa to your computer and use it in GitHub Desktop.
Check to see how much time you've spent listening to an album
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
//Make sure the entire page is loaded, zoom waaay out so all songs are visible. | |
//Check with this | |
var total = 0; | |
[...document.querySelectorAll(".songlist-container tbody > tr.song-row")].forEach(obj => { | |
const a = obj.children[2]; | |
const duration = a.innerText; | |
const t = obj.children[6]; | |
if (!t) { | |
console.log(obj) | |
return | |
} | |
const times = t.innerText; | |
const seconds = toSeconds(duration); | |
const final = seconds * times; | |
total += final; | |
}); | |
console.log(secondsToHms(total)); | |
function toSeconds(time) { | |
const parts = time.split(":"); | |
const minutes = Number(parts[0]); | |
const seconds = Number(parts[1]); | |
return seconds + minutes * 60; | |
} | |
function secondsToHms(d) { | |
d = Number(d); | |
const h = Math.floor(d / 3600); | |
const m = Math.floor(d % 3600 / 60); | |
const s = Math.floor(d % 3600 % 60); | |
const hDisplay = h > 0 ? h + (h == 1 ? " hour, " : " hours, ") : ""; | |
const mDisplay = m > 0 ? m + (m == 1 ? " minute, " : " minutes, ") : ""; | |
const sDisplay = s > 0 ? s + (s == 1 ? " second" : " seconds") : ""; | |
return hDisplay + mDisplay + sDisplay; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment