<commit_before>(function() {

  Blink = {};

  // Comms stuff

  var ws = location.href.replace("http", "ws");
  if (!/\/\d+$/.test(ws)) {
    ws += '/' + id;
  }
  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 = {};

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

  function cb(id, data) {
    data === undefined && (data = null);
    msg('callback', {callback: id, result: data});
  }

  handlers.eval = function(data) {
    var result = eval(data.code);
    if (data.callback) {
      result == undefined && (result = null);
      cb(data.callback, result);
    }
  }

  Blink.sock = sock;
  Blink.msg = msg;
  Blink.cb = cb;
  Blink.handlers = handlers;

  // JS eval

  function innertext(dom) {
    var children = dom.childNodes;
    if (children.length > 0) {
      return children[0].wholeText;
    } else {
      return "";
    }
  }

  function evalscripts(dom) {
    var scripts = dom.querySelectorAll("script");
    Array.prototype.forEach.call(scripts, function(s) {
      window.eval(innertext(s));
    });<commit_msg>support promises for async stuff<commit_after>(function() {

  Blink = {};

  // Comms stuff

  var ws = location.href.replace("http", "ws");
  if (!/\/\d+$/.test(ws)) {
    ws += '/' + id;
  }
  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 = {};

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

  function cb(id, data) {
    data === undefined && (data = null);
    if (data.constructor == Promise) {
      data.then(data => cb(id, data));
    } else {
      msg('callback', {callback: id, result: data});
    }
  }

  handlers.eval = function(data) {
    var result = eval(data.code);
    if (data.callback) {
      result == undefined && (result = null);
      cb(data.callback, result);
    }
  }

  Blink.sock = sock;
  Blink.msg = msg;
  Blink.cb = cb;
  Blink.handlers = handlers;

  // JS eval

  function innertext(dom) {
    var children = dom.childNodes;
    if (children.length > 0) {
      return children[0].wholeText;
    } else {
      return "";
    }
  }

  function evalscripts(dom) {
    var scripts = dom.querySelectorAll("script");
    Array.prototype.forEach.call(scripts, function(s) {
      window.eval(innertext(s));
    });
{'fraction_non_alphanumeric': 0.17297698589458055, 'fraction_numerical': 0.0014847809948032665, 'mean_word_length': 2.3942065491183877, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '3982213', 'n_tokens_mistral': 960, 'n_tokens_neox': 929, 'n_words': 199}