Created
August 19, 2011 18:21
-
-
Save sealabcore/1157575 to your computer and use it in GitHub Desktop.
Campfire Propane Entrance and Exit Music With Gifs
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
/* | |
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