window.onload = function() { const config = { "game": "testing", "user": "test_user", }; const rawHash = window.location.hash; if (rawHash) { const hash = rawHash.substr(1, rawHash.length).split(","); for (let i in hash) { let elements = hash[i].split(":"); if (elements.length != 2) { continue; } config[elements[0]] = elements[1]; } } const socket = new WebSocket("ws://localhost:8000/socket"); socket.addEventListener("open", function (event) { console.log("Connected to server!"); socket.send(JSON.stringify(config)); }); socket.addEventListener("message", function (event) { msg = JSON.parse(event.data); var chat = $(".chat"); chat.append(`
${msg.author}: ${msg.content}
`); chat.animate({scrollTop: chat.prop('scrollHeight')}); }); };