<commit_before>var ws = location.href.replace("http", "ws");
var sock = new WebSocket(ws);

function msg(t, m) {
  if (m == undefined) {
    m = t;
  } else {
    m.type = t;
  }
  sock.send(JSON.stringify(m));
}

var handlers = {};

handlers.eval = function(data) {
  var result = eval(data.code);
  if (data.callback) {
    result == undefined && (result = null);
    result = {type: 'callback', callback: data.callback, result: result};
    sock.send(JSON.stringify(result));
  }
}

sock.onmessage = function (event) {
  var msg = JSON.parse(event.data);
  if (handlers.hasOwnProperty(msg.type)) {
    handlers[msg.type](msg);
  }
};<commit_msg>modularise blink.js<commit_after>(function() {

  var ws = location.href.replace("http", "ws");
  var sock = new WebSocket(ws);

  function msg(t, m) {
    if (m == undefined) {
      m = t;
    } else {
      m.type = t;
    }
    sock.send(JSON.stringify(m));
  }

  var handlers = {};

  handlers.eval = function(data) {
    var result = eval(data.code);
    if (data.callback) {
      result == undefined && (result = null);
      result = {type: 'callback', callback: data.callback, result: result};
      sock.send(JSON.stringify(result));
    }
  }

  sock.onmessage = function (event) {
    var msg = JSON.parse(event.data);
    if (handlers.hasOwnProperty(msg.type)) {
      handlers[msg.type](msg);
    }
  };

  Blink = {
    sock: sock,
    msg: msg,
    handlers: handlers
  }
})();
{'fraction_non_alphanumeric': 0.17463617463617465, 'fraction_numerical': 0.0, 'mean_word_length': 2.902702702702703, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7096534', 'n_tokens_mistral': 514, 'n_tokens_neox': 504, 'n_words': 109}