Sha256: 20b1ddb58e9794cfbc01e7af535b2f038f3a888ab19d7ceb9009362dd1373207

Contents?: true

Size: 1.1 KB

Versions: 3

Compression:

Stored size: 1.1 KB

Contents

Campfire.RdioExpander = Class.create({
  initialize: function(chat) {
    this.chat = chat;
    var messages = this.chat.transcript.messages;
    for (var i = 0; i < messages.length; i++) {
      this.detectRdioURL(messages[i]);
    }
  },

  detectRdioURL: function(message) {
    if (!message.pending() && message.kind === 'text') {
      var body = message.bodyElement()
      var links = message.bodyElement().select('a:not(image)');

      for (var i = 0; i < links.length; i++) {
        var link = links[i];
        var href = link.getAttribute('href');
        var match = href.match(/^http:\/\/(rd\.io\/x\/\w*)$/)
        if (match) {
          var rdioHref = "rdio://" + match[1];
          link.setAttribute('href', rdioHref);
        }
      }
    }
  },

  onMessagesInsertedBeforeDisplay: function(messages) {
    for (var i = 0; i < messages.length; i++) {
      this.detectRdioURL(messages[i]);
    }
  },
  
  onMessageAccepted: function(message, messageID) {
    this.detectRdioURL(message);
  }

});

Campfire.Responders.push("RdioExpander");
window.chat.installPropaneResponder("RdioExpander", "rdioexpander");

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
caveat_patch_kids-0.0.8 scripts/caveat_patch_kids/link_to_rdio_app.js
caveat_patch_kids-0.0.7 scripts/caveat_patch_kids/link_to_rdio_app.js
caveat_patch_kids-0.0.4 scripts/caveat_patch_kids/link_to_rdio_app.js