bbs-reader.js
function extractColor(text, i, color) {
    var matches = [],
        match;
		
	text = text.slice(i);
    while ((match = text.match(/^\x1b\[([\d;]*)m/))) {
        matches.push(match);
        text = text.slice(match[0].length);
		i += match[0].length;
    }
    
    if (!matches.length) {
        return null;
    }
    
    var tokens = matches.map(function(match){
        return match[1].split(";");
    });
    
    tokens = Array.prototype.concat.apply([], tokens);
    
    var span = color.copy();
    span.i = i;
    
    var code;
    
    for (i = 0; i < tokens.length; i++) {
        code = +tokens[i];
        if (code == 0) {
            span.reset();
        } else if (code == 1) {
            span.l = true;
        } else if (code == 5) {
            span.flash = true;
        } else if (code == 7) {
            var t = span.f;
            span.f = span.b;
            span.b = t;
        } else if (code < 40) {
            span.f = code - 30;
        } else if (code < 50) {
            span.b = code - 40;
        }
    }
    return span;
}
function extractColor(text, i, color) {
    var matches = [],
        match;
		
	text = text.slice(i);
    while ((match = text.match(/^\x1b\[([\d;]*)m/))) {
        matches.push(match);
        text = text.slice(match[0].length);
		i += match[0].length;
    }
    
    if (!matches.length) {
        return null;
    }
    
    var tokens = matches.map(function(match){
        return match[1].split(";");
    });
    
    tokens = Array.prototype.concat.apply([], tokens);
    
    var span = color.copy();
    span.i = i;
    
    var code;
    
    for (i = 0; i < tokens.length; i++) {
        code = +tokens[i];
        if (code == 0) {
            span.reset();
        } else if (code == 1) {
            span.l = true;
        } else if (code == 5) {
            span.flash = true;
        } else if (code == 7) {
            var t = span.f;
            span.f = span.b;
            span.b = t;
        } else if (code < 40) {
            span.f = code - 30;
        } else if (code < 50) {
            span.b = code - 40;
        }
    }
    return span;
}
function extractColor ( text , i , color ) { var matches = [ ] , match ; text = text . slice ( i ) ; while ( ( match = text . match ( / ^\x1b\[([\d;]*)m / ) ) ) { matches . push ( match ) ; text = text . slice ( match [ 0 ] . length ) ; i += match [ 0 ] . length ; } if ( ! matches . length ) { return null ; } var tokens = matches . map ( function ( match ) { return match [ 1 ] . split ( ";" ) ; } ) ; tokens = Array . prototype . concat . apply ( [ ] , tokens ) ; var span = color . copy ( ) ; span . i = i ; var code ; for ( i = 0 ; i < tokens . length ; i ++ ) { code = + tokens [ i ] ; if ( code == 0 ) { span . reset ( ) ; } else if ( code == 1 ) { span . l = true ; } else if ( code == 5 ) { span . flash = true ; } else if ( code == 7 ) { var t = span . f ; span . f = span . b ; span . b = t ; } else if ( code < 40 ) { span . f = code - 30 ; } else if ( code < 50 ) { span . b = code - 40 ; } } return span ; }
extract text to color
extract text to color