Created
April 30, 2012 21:14
-
-
Save gfontenot/2562743 to your computer and use it in GitHub Desktop.
Propane hack to expand spotify artist and album urls to embedded players.
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
// Display Spotify songs inline | |
if (displaySpotifySongs) { | |
Campfire.SpotifyExpander = Class.create({ | |
initialize: function(chat) { | |
this.chat = chat; | |
var messages = this.chat.transcript.messages; | |
for (var i = 0; i < messages.length; i++) { | |
this.detectSpotifyURL(messages[i]); | |
} | |
}, | |
detectSpotifyURL: function(message) { | |
if (!message.pending() && message.kind === 'text') { | |
var links = message.bodyElement().select('a:not(image)'); | |
if (links.length != 1) { | |
return; | |
} | |
var href = links[0].getAttribute('href'); | |
var match = href.match(/^(http:\/\/|spotify:).*(track|album)(\/|:)(.*)$/); | |
if (!match) return; | |
message.resize((function() { | |
message.bodyCell.insert({bottom: '<iframe src="https://embed.spotify.com/?uri=spotify:' + match[2] + ':' + match[4] + '" width="300" height="80" frameborder="0" allowtransparency="true" ></iframe>'}); | |
})) | |
} | |
}, | |
onMessagesInsertedBeforeDisplay: function(messages) { | |
for (var i = 0; i < messages.length; i++) { | |
this.detectSpotifyURL(messages[i]); | |
} | |
}, | |
onMessageAccepted: function(message, messageID) { | |
this.detectSpotifyURL(message); | |
} | |
}); | |
Campfire.Responders.push("SpotifyExpander"); | |
window.chat.installPropaneResponder("SpotifyExpander", "spotifyexpander"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment