Skip to content

Instantly share code, notes, and snippets.

@dylanegan
Created March 17, 2011 00:46
Show Gist options
  • Save dylanegan/873646 to your computer and use it in GitHub Desktop.
Save dylanegan/873646 to your computer and use it in GitHub Desktop.
The Final Countdown, Gob and all that shawesomeness.
var theFinalCountdown = true;
if (theFinalCountdown) {
Campfire.TheFinalCountdown = Class.create({
initialize: function(chat) {
this.chat = chat;
this.id = 1;
this.images = ["http://26.media.tumblr.com/tumblr_li5rrfudu21qz64oio1_500.jpg", "http://images2.fanpop.com/images/photos/3600000/GOB-Animated-gif-arrested-development-3695155-284-152.gif"];
this.track = "http://dylanegan.com/etfc.mp3";
this.prefix = "etfc_";
this.slightlyLessAnnoying = false;
var messages = this.chat.transcript.messages;
for (var i = 0; i < messages.length; i++) {
this.gobEm(messages[i]);
}
},
gobEm: function(message, autoplay) {
var matches, src;
var image = message.bodyElement().getElementsByTagName('img')[0];
var autoplay = autoplay || "";
if (typeof image != "undefined" && image !== null && this.images.indexOf(image.src) >= 0) {
var audio = document.createElement('audio');
audio.src = this.track;
if (this.slightlyLessAnnoying !== false) {
audio.autoplay = autoplay;
}
audio.setAttribute("id", this.prefix + this.id);
image.setAttribute('data-audio-id', this.prefix + this.id);
document.body.insertBefore(audio);
this.id += 1;
image.onclick = function(e) {
e.preventDefault();
var audio = document.getElementById(this.getAttribute('data-audio-id'));
if (audio.paused) {
audio.play();
} else {
audio.pause();
}
}
}
},
onMessagesInsertedBeforeDisplay: function(messages) {
for (var i = 0; i < messages.length; i++) {
this.gobEm(messages[i], "autoplay");
}
}
});
Campfire.Responders.push("TheFinalCountdown");
window.chat.installPropaneResponder("TheFinalCountdown", "thefinalcountdown");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment