<commit_before>//init
//generate uniq seesion id for terminal
var sessionId =  randomString(32, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
var history = new  Array();
var historyShift = 0;

$(function() {
    $("#con").keypress(function(ev) {
        if (ev.which == 13){ //enter
			command = $("#con").val();
			history.push(command);
			historyShift = 0;
			if(history.length>20){
				history.shift();
			}
			if(command=="/clear"){
				$("#log").html("");
				$("#con").val("");
				return;
			}
			$("#con").val("");
			$.post("command.php", {command: command, sessionId: sessionId});
		}
		
    });
	
	$("#con").keydown(function(ev) {
		if (ev.keyCode == 38){ //up arrow
			ev.preventDefault();
			historyShift++;
			if(historyShift > history.length){
				historyShift = history.length;
			}
			prevCommand = history[history.length - historyShift];
			$("#con").val(prevCommand);
		}
		if (ev.keyCode == 40){ //down arrow
			historyShift--;
			if(historyShift<0){
				historyShift = 0;
			}
			if(historyShift==0){
				$("#con").val("");
			}else{
				ev.preventDefault();
				prevCommand = history[history.length - historyShift];
				$("#con").val(prevCommand);
			}
		}
	});
	
    $("#con").focus();
    $("#log").click(function() {
        $("#con").focus();
    });

    longPoll(); //start loop
});

function escapeHtml(t){
	return $('<div/>').text(t).html();
}


function randomString(length, chars) {
    var result = '';
    for (var i = length; i > 0; --i) result += chars[Math.round(Math.random() * (chars.length - 1))];
    return result;
}

function handleServerMessage(data) {
        json = $.parseJSON(data);
        if (json.result == "success") {
            $("#log").append("<br/>");
            str = json.message;
            message = $.parseJSON(str);
            for (line in message.lines) {
				_line = message.lines[line];
                pre = '<pre class="server">'+timeStamp();
				
				for (shard in _line.shards){
					_shard = _line.shards[shard];
					span = '<span';
					if(_shard.color){
						span+=' style="color:#'+_shard.color+'"';
					}
					span+= '>'+escapeHtml(_shard.text)+'</span>';
					pre+= span;
				}
                pre+= '</pre>';
                $("#log").append(pre);
            }

            $("#log").scrollTop($("#log")[0].scrollHeight);
			gotANewMessage();
        }

}

function pad(n){
	return n<10 ? '0' + n : n
}

function timeStamp(){
	today = new Date();
	h=pad(today.getHours());
	m=pad(today.getMinutes());
	s=pad(today.getSeconds());
	return '['+h+':'+m+':'+s+'] ';
}

function longPoll()
{
    $.post('ajax.php', {sessionId: sessionId},function(data)
    {
        handleServerMessage(data);
        longPoll();
    });
}

var blinkInterval;

function gotANewMessage() {
  if(!window.hasfocus) { 
    blinkInterval = window.setInterval(blink, 500);
  }
}

function blink() {
	if(window.blinkOn && !window.hasfocus) {
		document.title = "The room [!]"; 
		window.blinkOn = false; 
	} else {
		document.title = "The room"; 
		window.blinkOn = true; 
	}
}

window.hasfocus = false;

window.onfocus = function() { 
  if(blinkInterval) window.clearInterval(blinkInterval); 
  blinkInterval = false;
  this.hasfocus = true;
  document.title = "The room"; 
}

window.onblur = function(){
   this.hasfocus = false;
}<commit_msg>focus issue<commit_after>//init
//generate uniq seesion id for terminal
var sessionId =  randomString(32, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
var history = new  Array();
var historyShift = 0;

$(function() {
    $("#con").keypress(function(ev) {
        if (ev.which == 13){ //enter
			command = $("#con").val();
			history.push(command);
			historyShift = 0;
			if(history.length>20){
				history.shift();
			}
			if(command=="/clear"){
				$("#log").html("");
				$("#con").val("");
				return;
			}
			$("#con").val("");
			$.post("command.php", {command: command, sessionId: sessionId});
		}
		
    });
	
	$("#con").keydown(function(ev) {
		if (ev.keyCode == 38){ //up arrow
			ev.preventDefault();
			historyShift++;
			if(historyShift > history.length){
				historyShift = history.length;
			}
			prevCommand = history[history.length - historyShift];
			$("#con").val(prevCommand);
		}
		if (ev.keyCode == 40){ //down arrow
			historyShift--;
			if(historyShift<0){
				historyShift = 0;
			}
			if(historyShift==0){
				$("#con").val("");
			}else{
				ev.preventDefault();
				prevCommand = history[history.length - historyShift];
				$("#con").val(prevCommand);
			}
		}
	});
	
    $("#con").focus();
    $("#log").click(function() {
        $("#con").focus();
    });

    longPoll(); //start loop
});

function escapeHtml(t){
	return $('<div/>').text(t).html();
}


function randomString(length, chars) {
    var result = '';
    for (var i = length; i > 0; --i) result += chars[Math.round(Math.random() * (chars.length - 1))];
    return result;
}

function handleServerMessage(data) {
        json = $.parseJSON(data);
        if (json.result == "success") {
            $("#log").append("<br/>");
            str = json.message;
            message = $.parseJSON(str);
            for (line in message.lines) {
				_line = message.lines[line];
                pre = '<pre class="server">'+timeStamp();
				
				for (shard in _line.shards){
					_shard = _line.shards[shard];
					span = '<span';
					if(_shard.color){
						span+=' style="color:#'+_shard.color+'"';
					}
					span+= '>'+escapeHtml(_shard.text)+'</span>';
					pre+= span;
				}
                pre+= '</pre>';
                $("#log").append(pre);
            }

            $("#log").scrollTop($("#log")[0].scrollHeight);
			gotANewMessage();
        }

}

function pad(n){
	return n<10 ? '0' + n : n
}

function timeStamp(){
	today = new Date();
	h=pad(today.getHours());
	m=pad(today.getMinutes());
	s=pad(today.getSeconds());
	return '['+h+':'+m+':'+s+'] ';
}

function longPoll()
{
    $.post('ajax.php', {sessionId: sessionId},function(data)
    {
        handleServerMessage(data);
        longPoll();
    });
}

var blinkInterval;

function gotANewMessage() {
  if(!window.hasfocus) { 
    blinkInterval = window.setInterval(blink, 500);
  }
}

function blink() {
	if(window.blinkOn && !window.hasfocus) {
		document.title = "The room [!]"; 
		window.blinkOn = false; 
	} else {
		document.title = "The room"; 
		window.blinkOn = true; 
	}
}

window.hasfocus = true;

window.onfocus = function() { 
  if(blinkInterval) window.clearInterval(blinkInterval); 
  blinkInterval = false;
  this.hasfocus = true;
  document.title = "The room"; 
}

window.onblur = function(){
   this.hasfocus = false;
}
{'fraction_non_alphanumeric': 0.20261929850970947, 'fraction_numerical': 0.010236339003462292, 'mean_word_length': 2.871794871794872, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6084130', 'n_tokens_mistral': 2592, 'n_tokens_neox': 2272, 'n_words': 415}