diff --git a/main.js b/main.js index d664656..5662a8e 100644 --- a/main.js +++ b/main.js @@ -48,7 +48,7 @@ document.querySelector('.form__input-submit').addEventListener('click', function function getMessages() { const timestamp = (document.querySelector('.chat').lastElementChild) ? document.querySelector('.chat').lastElementChild.getAttribute('data-timestamp') : 0 - fetch('api.php?action=getMessages×tamp=' + timestamp) + return fetch('api.php?action=getMessages×tamp=' + timestamp) .then(function (data) { return data.json() }) @@ -106,7 +106,10 @@ function createMessageNode(name, text, timestamp, datetime) { return true } -getMessages() +getMessages().then(() => { + scrollWindowDown() +}) + setInterval(function () { getMessages() }, 2000)