<commit_before>
console.log(
  'Welcome to Corsica.\n'+
  'To the NORTH there is water.\n'+
  'To the WEST there is water.\n'+
  'To the EAST there is water.\n'+
  'To the SOUTH there is water.'
);

var config;
try {
  config = localStorage.getItem('config');
  if (config) {
    config = JSON.parse(config);
    if (config) {
      console.log('Welcome back, old friend.');
    } else {
      config = undefined;
    }
  }
} catch (e) {
  console.warn('Config could not be parsed: ' + e);
}
if (!config) {
  console.log('You\'re new here, aren\'t you.');
  config = {};
}

function writeConfig() {
  try {
    localStorage.setItem('config', JSON.stringify(config));
  } catch (e) {
    console.warn('Config could not be written.');
  }
}

function payAttention(name) {
  if (name instanceof Array) {
    for (var i=0; i<name.length; i++) {
      if (name[i] === config.name) {
        return true;
      }
    }
    return false;
  }
  return config.name === name;
}

function identify() {
  toast('I am ' + config.name, 10000);
}

var toastTimeout;
var toastEl = document.querySelector('#toast');
function toast(message, timeout) {
  toastEl.textContent = message;
  toastEl.classList.add('show');
  toastTimeout = setTimeout(untoast, timeout || 5000);
}
function untoast() {
  toastEl.classList.remove('show');
}

var contentEl = document.querySelector('#content');

function handleURL(url) {
  var iframe = makeEl('iframe', null, {
    sandbox: 'allow-same-origin allow-scripts allow-forms',
    src: url
  });
  contentEl.innerHTML = '';
  contentEl.appendChild(iframe);
}

function handleHTML(html) {
  contentEl.innerHTML = '';
  var blob = new Blob([html], { "type" : "text/html" });
  var url = URL.createObjectURL(blob);
  var iframe = makeEl('iframe', null, {
    sandbox: 'allow-same-origin allow-scripts allow-forms',
    src: url
  });
  contentEl.appendChild(iframe);
}

function init() {
  console.log('My name is ' + config.name);
  sendMessage('init', {name: config.name});
  setupFullscreen();
}

console.log('Waiting for connection to server...');

socket.on('connect', function() {
  console.log('Connection to server established.');

  if (config.name === undefined) {
    console.log('getting a name');
    sendMessage('getName').then(function(message) {
      config.name = message.name;
      console.log(message);
      writeConfig();
      init();
    });
  } else {
    init();
  }
});

socket.on('admin', function (msg) {
  var type = msg.type;
  if (!type) {
    return;
  }
  if (!payAttention(msg.screen)) {
    console.log('You receive a message, but it\'s not for you...');
    return;
  }
  switch (type) {
    case 'reload':
      window.location.reload();
      break;
  }
});

socket.on('toast', function (msg) {
  if (!payAttention(msg.screen)) {
    console.log('You receive a message, but it\'s not for you...');
    return;
  }
  if (msg.text) {
    toast(msg.text);
  }
});

socket.on('identify', function (msg) {
  if (payAttention(msg.screen)) {<commit_msg>add optional timeout param for toast<commit_after>
console.log(
  'Welcome to Corsica.\n'+
  'To the NORTH there is water.\n'+
  'To the WEST there is water.\n'+
  'To the EAST there is water.\n'+
  'To the SOUTH there is water.'
);

var config;
try {
  config = localStorage.getItem('config');
  if (config) {
    config = JSON.parse(config);
    if (config) {
      console.log('Welcome back, old friend.');
    } else {
      config = undefined;
    }
  }
} catch (e) {
  console.warn('Config could not be parsed: ' + e);
}
if (!config) {
  console.log('You\'re new here, aren\'t you.');
  config = {};
}

function writeConfig() {
  try {
    localStorage.setItem('config', JSON.stringify(config));
  } catch (e) {
    console.warn('Config could not be written.');
  }
}

function payAttention(name) {
  if (name instanceof Array) {
    for (var i=0; i<name.length; i++) {
      if (name[i] === config.name) {
        return true;
      }
    }
    return false;
  }
  return config.name === name;
}

function identify() {
  toast('I am ' + config.name, 10000);
}

var toastTimeout;
var toastEl = document.querySelector('#toast');
function toast(message, timeout) {
  toastEl.textContent = message;
  toastEl.classList.add('show');
  toastTimeout = setTimeout(untoast, timeout || 5000);
}
function untoast() {
  toastEl.classList.remove('show');
}

var contentEl = document.querySelector('#content');

function handleURL(url) {
  var iframe = makeEl('iframe', null, {
    sandbox: 'allow-same-origin allow-scripts allow-forms',
    src: url
  });
  contentEl.innerHTML = '';
  contentEl.appendChild(iframe);
}

function handleHTML(html) {
  contentEl.innerHTML = '';
  var blob = new Blob([html], { "type" : "text/html" });
  var url = URL.createObjectURL(blob);
  var iframe = makeEl('iframe', null, {
    sandbox: 'allow-same-origin allow-scripts allow-forms',
    src: url
  });
  contentEl.appendChild(iframe);
}

function init() {
  console.log('My name is ' + config.name);
  sendMessage('init', {name: config.name});
  setupFullscreen();
}

console.log('Waiting for connection to server...');

socket.on('connect', function() {
  console.log('Connection to server established.');

  if (config.name === undefined) {
    console.log('getting a name');
    sendMessage('getName').then(function(message) {
      config.name = message.name;
      console.log(message);
      writeConfig();
      init();
    });
  } else {
    init();
  }
});

socket.on('admin', function (msg) {
  var type = msg.type;
  if (!type) {
    return;
  }
  if (!payAttention(msg.screen)) {
    console.log('You receive a message, but it\'s not for you...');
    return;
  }
  switch (type) {
    case 'reload':
      window.location.reload();
      break;
  }
});

socket.on('toast', function (msg) {
  if (!payAttention(msg.screen)) {
    console.log('You receive a message, but it\'s not for you...');
    return;
  }
  if (msg.text) {
    toast(msg.text,  msg.timeout);
  }
});

socket.on('identify', function (msg) {
  if (payAttention(msg.screen)) {
{'fraction_non_alphanumeric': 0.1701705015725873, 'fraction_numerical': 0.0033107101473266016, 'mean_word_length': 3.2340574632095307, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3551687', 'n_tokens_mistral': 2037, 'n_tokens_neox': 2024, 'n_words': 496}