Skip to content

Instantly share code, notes, and snippets.

@jwkblades
Created May 27, 2014 18:56
Show Gist options
  • Save jwkblades/d5232eed52c81bab3080 to your computer and use it in GitHub Desktop.
Save jwkblades/d5232eed52c81bab3080 to your computer and use it in GitHub Desktop.
music.xbox.com duration calculation bookmarklet

music.xbox.com now playing duration calculator

This bookmarklet calculates the duration of your currently-loaded Now Playing tab. It does this by looking at all of their duration elements on the page, parsing them, summing them, and then breaking that up into hours, minutes, and seconds, which it adds to the top bar (secondaryMetadata).

Usage

Usage is simple. Create a bookmark with a custom URL, and add the code from duration_bookmarklet.js to it as the URL. Name the bookmark whatever you want and when you want to see your Now Playing duration, assuming you are on the Now Playing page and have the entire playlist loaded, you can click on the bookmark to have it calculated for you.

Tested In

At this point I have only tested this code in Chromium, but all modern browsers should work. Requires document.querySelector and document.querySelectorAll.

javascript:(function(){var durationElements = document.querySelectorAll("[data-bind='text: duration']"); var duration = 0; for(var i = 0; i < durationElements.length; i++){ var s = (durationElements[i].innerHTML).split(":"); duration += parseInt(s[0]*60) + parseInt(s[1]); }; var hours = Math.floor(duration / 3600); var minutes = Math.floor((duration % 3600) / 60); var seconds = Math.floor((duration % 3600) % 60); document.querySelector(".secondaryMetadata").innerHTML += ", duration: " + hours + " hours " + minutes + " minutes and " + seconds + " seconds";}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment