/* House keeping */ var socket = new WebSocket('wss://' + document.domain + SCRIPT_NAME + '/ws/quest/' + quest_id + '/'); socket.oldSend = socket.send; socket.send = function(event_title, data) { data = JSON.stringify({event: event_title, data: data}); socket.oldSend.apply(this, [data]); } socket.events = {}; socket.onmessage = function(e) { let data = JSON.parse(e.data); let event = data.event; data = data.data; if (socket.events[event] === undefined) { return; } socket.events[event](data); } function load() { document.getElementById('chatWindow').scrollTop = document.getElementById('chatWindow').scrollHeight; let mtarea = document.getElementById('messageTextArea'); mtarea.addEventListener('keypress', function(event) { if (event.key == 'Enter' && !event.shiftKey) { let text = mtarea.value.trim(); mtarea.value = ''; if (text == '') { return; } document.getElementById('chatWindow').scrollTop = document.getElementById('chatWindow').scrollHeight; socket.send('message', {message: text, quest_id: quest_id}); } }); } /* Websocket events */ socket.events['message'] = function(data) { let msg_str = '
'; post_str += ' | '; post_str += '' + data.options[i][1] + ' | '; post_str += '0 |