Sha256: 5e9f7960b0c18734062626560e10477a059a182d78cf1a55c14b6261d2fea038

Contents?: true

Size: 1.22 KB

Versions: 4

Compression:

Stored size: 1.22 KB

Contents

// from https://gist.github.com/1481799
Campfire.YouTube = Class.create({
  initialize: function(chat) {
    this.chat = chat;
    var messages = this.chat.transcript.messages;
    for (var i = 0; i < messages.length; i++) {
      this.detectYouTubeURL(messages[i]);
    }
  },

  detectYouTubeURL: function(message) {
    if (!message.pending() && message.kind === 'text') {

if(message.bodyElement().innerHTML.match(/http:\/\/www\.youtube\.com\//)){

  setTimeout(function(){
    var links = message.bodyElement().select('a');
        if (!links.length) {
          return;
              }
        var href = links[0].getAttribute('href');
    var vid_id = href.split("v=")[1].split(/\&amp;|\&|,|%2C/)[0];
    message.bodyElement().innerHTML  = '<iframe width="420" height="315" src="http://www.youtube.com/embed/'+ vid_id+ '" frameborder="0" allowfullscreen></iframe>' ;
  },300);
}
    }
  },
  onMessagesInsertedBeforeDisplay: function(messages) {
    for (var i = 0; i < messages.length; i++) {
      this.detectYouTubeURL(messages[i]);
    }
  },

  onMessageAccepted: function(message, messageID) {
    this.detectYouTubeURL(message);
  }
});

Campfire.Responders.push("YouTube");
window.chat.installPropaneResponder("YouTube", "youtube");

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
caveat_patch_kids-0.0.8 scripts/caveat_patch_kids/embed_youtube.js
caveat_patch_kids-0.0.7 scripts/caveat_patch_kids/embed_youtube.js
caveat_patch_kids-0.0.5 scripts/caveat_patch_kids/embed_youtube.js
caveat_patch_kids-0.0.4 scripts/caveat_patch_kids/embed_youtube.js