(async () => { // check notification permission await Notification.requestPermission() })() const tournaments = JSON.parse(document.getElementById('tournaments_list').textContent) const sockets = {} const messages = document.getElementById('messages') function abortDraw(tid) { sockets[tid].send(JSON.stringify({'type': 'abort'})) } function drawDice(tid, trigram = null) { sockets[tid].send(JSON.stringify({'type': 'dice', 'trigram': trigram})) } function drawProblem(tid) { sockets[tid].send(JSON.stringify({'type': 'draw_problem'})) } function acceptProblem(tid) { sockets[tid].send(JSON.stringify({'type': 'accept'})) } function rejectProblem(tid) { sockets[tid].send(JSON.stringify({'type': 'reject'})) } function showNotification(title, body, timeout = 5000) { let notif = new Notification(title, {'body': body, 'icon': "/static/tfjm.svg"}) if (timeout) setTimeout(() => notif.close(), timeout) } document.addEventListener('DOMContentLoaded', () => { if (document.location.hash) { document.querySelectorAll('button[data-bs-toggle="tab"]').forEach(elem => { if ('#' + elem.innerText.toLowerCase() === document.location.hash.toLowerCase()) { elem.click() } }) } document.querySelectorAll('button[data-bs-toggle="tab"]').forEach( elem => elem.addEventListener( 'click', () => document.location.hash = '#' + elem.innerText.toLowerCase())) for (let tournament of tournaments) { let socket = new WebSocket( (document.location.protocol === 'https:' ? 'wss' : 'ws') + '://' + window.location.host + '/ws/draw/' + tournament.id + '/' ) sockets[tournament.id] = socket function addMessage(message, type, timeout = 0) { const wrapper = document.createElement('div') wrapper.innerHTML = [ `