close

  
<div><p> /*global jQuery */
// Define: Linkify plugin
(function($){
  
  var url1 = /(^|&lt;|\s)(www\..+?\..+?)(\s|&gt;|$)/g,
      url2 = /(^|&lt;|\s)(((https?|ftp):\/\/|mailto:).+?)(\s|&gt;|$)/g,
      
      linkifyThis = function () {
        var childNodes = this.childNodes,
            i = childNodes.length;
        while(i--) {
          var n = childNodes[i];
          if (n.nodeType === 3) {
            var html = $.trim(n.nodeValue);
            if (html)
            {
              html = html.replace(/&amp;/g, '&amp;')
                .replace(//g, '&gt;')
                .replace(url1, '$1<a href="http://%242">$2</a>$3')
                .replace(url2, '$1<a href="%242">$2</a>$5');
              $(n).after(html).remove();
            }
          }
          else if (n.nodeType === 1  &amp;&amp;  !/^(a|button|textarea)$/i.test(n.tagName)) {
            linkifyThis.call(n);
        }
      }
      };
  
  $.fn.linkify = function () {
    return this.each(linkifyThis);
  };
  
})(jQuery);

/*global $ console document */

// TODO: add dynamic formatting to the logs

$(function() {
  // Make urls into clickable links - consider any line that contains a slash
  $('b:contains(/)').linkify();
  
  // Clarify what JOIN, LEAVE, QUIT mean:
  $('.JOIN&gt;b,.LEAVE&gt;b,.QUIT&gt;b').each(function(index,elm) {
    var $e = $(elm);
    var $p = $e.parent();
    var label = 'Left. ';
    if      ($p.hasClass('JOIN')) { label='Joined. '; }
    else if ($p.hasClass('QUIT')) { label='Quit. ';   }
    var t = label + $e.text();
    $e.text(t);
  });
    
  function mark_msgs_read_by(username) {
    //console.log('Marking messages which were read by '+username);
    var absent=true;
    var userjoin='.user-'+username; // any activity by this person indicates their presence
    var userquit='.QUIT.user-'+username;
    $('div').filter(function() {
      var $this=$(this); 
      if ($this.is(userjoin)) { absent=false; }
      if ($this.is(userquit)) { absent=true;  }
      return !absent;
    }).toggleClass('read');
  }
  
  // make user-names highlightable
  $('s').click(function(e) {
    var c=$(e.target).closest('div').attr('class');
    var username = /user-\w+/.exec(c)[0];
    $('.'+username).toggleClass('highlight');
  });
  
  var channel = /(\w+)\.html/.exec(document.location.href)[1];
  var about_url =  'http://acrebot.freebaseapps.com/' + channel;

  // add the control bar
  var CONTROLS_HTML = [
    '</p><div class="about"><a href="'+about_url+'">About #'+channel+'</a></div>',
    '<div class="controls" title="Hide converstation that occured while you where logged in">',
    '  Username: ',
    '</div>',
    ''].join('\n');
  $(document.body).append(CONTROLS_HTML);
  //console.warn('cookie == ',document.cookie);
  var r = /read-by=(.+?)(;|$)/.exec(document.cookie);
  if (r &amp;&amp; r[1]) {
    var username = r[1];
    $('#read-by').val(username);
    mark_msgs_read_by(username);
  }
  
  
  //wire it up
  $('#read-by').change(function() {
    $('.read').removeClass('read');
    var username = $(this).val();
    var p = document.location.pathname.split('/'); p.pop(); p = p.join('/');
    var d = new Date("Jan 1 2030").toGMTString();
    var cookie = 'read-by='+username+';path='+p+';expires='+d; // store for any log
    //console.warn('cooke = ',cookie);
    document.cookie = cookie;
    mark_msgs_read_by(username);
  });
  
});

 </div>

Comments

Hide