Skip to content

Instantly share code, notes, and snippets.

@sealabcore
Created August 19, 2011 18:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sealabcore/1157575 to your computer and use it in GitHub Desktop.
Save sealabcore/1157575 to your computer and use it in GitHub Desktop.
Campfire Propane Entrance and Exit Music With Gifs
/*
Play entrance music
*/
/* defining a new responder is probably the best way to insulate your hacks from Campfire and Propane */
Campfire.EntranceMusician = Class.create({
initialize: function(chat) {
this.chat = chat;
var messages = this.chat.transcript.messages;
for (var i = 0; i < messages.length; i++) {
var message = messages[i];
if (message.bodyElement().innerText.match(/has entered the room/)) {
var author = message.authorElement().innerText.replace(".", "").replace(" ", "");
var gif_location = '<img src=' + '\"http://theme-music.s3.amazonaws.com/'.concat(author, '.gif\"') + '>';
message.bodyElement().innerHTML = gif_location;
}
}
setTimeout(function delayedScroll() {
this.chat.windowmanager.scrollToBottom();
}, 500);
},
onMessagesInserted: function(messages) {
for (var i = 0; i < messages.length; i++) {
var message = messages[i];
var author = message.authorElement().innerText.replace(".", "").replace(" ", "");
if (message.bodyElement().innerText.match(/has entered the room/)) {
this.playSoundForPerson(author, 'Entrance', message);
}
if (message.bodyElement().innerText.match(/has left the room/)) {
this.playSoundForPerson(author, 'Exit', message);
}
}
},
playSoundForPerson: function(author, type, message) {
var audio = document.createElement('audio');
audio.src = 'http://theme-music.s3.amazonaws.com/'.concat(author, type, '.mp3');
audio.autoplay = true;
document.body.insertBefore(audio);
var gif_location = '<img src=' + '\"http://theme-music.s3.amazonaws.com/'.concat(author, '.gif\"') + '>';
if (type === 'Entrance') {
message.bodyElement().innerHTML = gif_location;
}
setTimeout(function alertMessage() {
this.chat.windowmanager.scrollToBottom();
}, 500);
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment