Skip to content

Instantly share code, notes, and snippets.

@TristanWiley
Last active March 11, 2019 23:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TristanWiley/4c839cf3c42550dd8ffb3685f01c0caa to your computer and use it in GitHub Desktop.
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
//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