window.addEventListener('load', () => {
  let pushedbox = document.getElementById('pushedteam');
  let form = document.getElementById('form');
  //let sendMsg = document.getElementById('send-msg');
  let ws = new WebSocket('ws://' + window.location.host + '/websocket');

  ws.onopen = () => console.log('connection opened');
  ws.onclose = () => console.log('connection closed');
  ws.onmessage = m => {
    if (m.data=="Delete!") {
      while (pushedbox.firstChild) pushedbox.removeChild(pushedbox.firstChild);
      document.getElementById('push').disabled = false;
    } else {
      let li = document.createElement('li');
      li.textContent = m.data;
      pushedbox.append(li);
    };
  };

  //sendMsg.addEventListener('click', () => sendMsg.value = '');

  form.addEventListener('submit', e => {
    document.getElementById('push').disabled = true;
    ws.send("Stop!"); //
    //sendMsg.value = ''; //sendMsgを空にして初期状態に
    e.preventDefault(); //form送信して送信先のページに遷移する動作をキャンセル
  });
});
