var term,
    protocol,
    socketURL,
    socket,
    repl_name,
    charWidth,
    charHeight;

var terminalContainer = document.getElementById('terminal-container');

function setTerminalSize () {
  var cols = parseInt(colsElement.value),
      rows = parseInt(rowsElement.value),
      width = (cols * charWidth).toString() + 'px',
      height = (rows * charHeight).toString() + 'px';

  terminalContainer.style.width = width;
  terminalContainer.style.height = height;
  term.resize(cols, rows);
}


createTerminal();

function createTerminal() {
  // Clean terminal
  while (terminalContainer.children.length) {
    terminalContainer.removeChild(terminalContainer.children[0]);
  }
  term = new Terminal({
    cursorBlink: false
  });
  term.on('resize', function (size) {
    if (!repl_name) {
      return;
    }
    var cols = size.cols,
        rows = size.rows,
        url = '/terminals/' + repl_name + '/size?cols=' + cols + '&rows=' + rows;

    fetch(url, {method: 'POST'});
  });
  protocol = (location.protocol === 'https:') ? 'wss://' : 'ws://';
  socketURL = protocol + location.hostname + ((location.port) ? (':' + location.port) : '') + '/ws/';

  term.open(terminalContainer);
  term.fit();
  // term.toggleFullscreen(1);

  var initialGeometry = term.proposeGeometry(),
      cols = initialGeometry.cols,
      rows = initialGeometry.rows;


  fetch('/terminals?cols=' + cols + '&rows=' + rows, {method: 'POST'}).then(function (res) {

    if(!res.ok) {
      if(res.status == 429)
        document.getElementById("overlay").innerText = "Too many requests from this IP, please try again after 30 minutes";
      else
        document.getElementById("overlay").innerText = res.statusText;

      notify();
      return;
    }

    charWidth = Math.ceil(term.element.offsetWidth / cols);
    charHeight = Math.ceil(term.element.offsetHeight / rows);

    res.text().then(function (repl_name) {
      window.repl_name = repl_name;
      socketURL += repl_name;
      socket = new WebSocket(socketURL);
      socket.onopen = runRealTerminal;
      socket.onclose = notify;
      socket.onerror = notify;
    });
  }).catch(function(err) {
    document.getElementById("overlay").innerText = err;
    notify();
  });;
}

function notify() {
  terminalContainer.style.opacity = 0.5;
  document.getElementById("overlay").style.display = "block";
}

function runRealTerminal() {
  term.attach(socket);
  term._initialized = true;
}

@@ -1,15 +1,15 @@
-var
+let
  term,%0A    p
@@ -91,19 +91,21 @@
 eight;%0A%0A
-var
+const
  termina
@@ -165,24 +165,21 @@
 ner');%0A%0A
-function
+const
  setTerm
@@ -190,19 +190,26 @@
 Size
+ =
  ()
+ =%3E
  %7B%0A  
-var
+const
  col
@@ -508,36 +508,13 @@
 %0A%7D%0A%0A
-%0AcreateTerminal();%0A%0Afunction
+const
  cre
@@ -520,26 +520,32 @@
 eateTerminal
-()
+ = () =%3E
  %7B%0A  // Clea
@@ -808,19 +808,21 @@
   %7D%0A    
-var
+const
  cols = 
@@ -1236,11 +1236,13 @@
 %0A%0A  
-var
+const
  ini
@@ -1432,22 +1432,17 @@
 hen(
-function
  (res)
+ =%3E
  %7B%0A%0A
@@ -1874,24 +1874,16 @@
 ().then(
-function
  (repl_n
@@ -1878,32 +1878,35 @@
 hen( (repl_name)
+ =%3E
  %7B%0A      window.
@@ -2123,21 +2123,17 @@
 tch(
-function
+ 
 (err)
+ =%3E
  %7B%0A 
@@ -2215,25 +2215,47 @@
 %0A%7D%0A%0A
-function notify()
+createTerminal();%0A%0Aconst notify = () =%3E
  %7B%0A 
@@ -2359,24 +2359,21 @@
 ck%22;%0A%7D%0A%0A
-function
+const
  runReal
@@ -2380,18 +2380,24 @@
 Terminal
-()
+ = () =%3E
  %7B%0A  ter

use es5