js.js 713 B

12345678910111213141516171819202122232425
  1. const socket = io("http://socketchat.fs.a-level.com.ua/")
  2. socket.on('msg', msg=>messenger(msg));
  3. send.onclick = function(){
  4. socket.emit('msg', {nick: nick.value, message: message.value});
  5. }
  6. function messenger(users){
  7. var chat = document.getElementById('chat');
  8. var dataInput = document.createElement('p');
  9. chat.appendChild(dataInput);
  10. dataInput.style.padding = '8px';
  11. dataInput.style.margin = '2px 20px';
  12. dataInput.style.color = 'white';
  13. dataInput.style.fontWeight = 'bold';
  14. dataInput.innerText = users.nick + ': ' + users.message;
  15. if(users.nick === 'Emmanuil'){
  16. dataInput.style.display = 'flex';
  17. dataInput.style.flexDirection = 'row-reverse';
  18. }
  19. }