Skip to content

Instantly share code, notes, and snippets.

@baileylo
Created October 1, 2013 18:52
Show Gist options
  • Save baileylo/6783242 to your computer and use it in GitHub Desktop.
Save baileylo/6783242 to your computer and use it in GitHub Desktop.
Code to create spotify openable links.
// starts with spotify:track
// used defined input
input = 'spotify:track:6MdqqkQ8sSC0WB4i8PyRuQ';
var parts = input.match(/spotify\:track\:(.+)/)
if (parts.length !== 2) {
return input;
}
var song_id = parts[1],
url = 'http://logansbailey.com/ogp/?q=http://open.spotify.com/track/' + song_id,
request = new XMLHttpRequest();
request.open('get', url, true);
request.onload = function() {
var response = httpRequest.response;
if (!response || !JSON.parse(httpRequest.response)) {
response = {description: 'Unknown track on spotify'};
} else {
response = JSON.parse(httpRequest.response);
}
return '<a target="_blank" href="spotify://track:' + song_id + '">' response.description'</a>';
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment