From d030eda0e9ed6bf68e4936aebb15c03a5717b3ac Mon Sep 17 00:00:00 2001 From: Arindy Date: Sat, 22 Feb 2025 12:16:22 +0100 Subject: [PATCH] reregister users on roll --- src/main/resources/META-INF/resources/app.js | 54 +++++++++++--------- src/main/resources/templates/index.html | 5 +- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/src/main/resources/META-INF/resources/app.js b/src/main/resources/META-INF/resources/app.js index 7fe0ec2..6c96c24 100644 --- a/src/main/resources/META-INF/resources/app.js +++ b/src/main/resources/META-INF/resources/app.js @@ -14,6 +14,17 @@ function url() { return window.location.protocol + '//' + window.location.hostname + (window.location.port?.length > 0 ? ':' + window.location.port : ''); } +function register() { + let httpRequest = new XMLHttpRequest(); + httpRequest.open('POST', url() + '/dice/' + document.getElementById('room').value + '/register') + httpRequest.setRequestHeader('Content-Type', 'application/json') + httpRequest.send(JSON.stringify({ + name: document.getElementById('name').value, + overlay: document.getElementById('overlayId').value, + id: document.getElementById('room').value + ':' + localStorage.getItem('userId') + })) +} + function start(event = undefined) { if ((!event || event.keyCode === 13) && document.getElementById('name').value.length > 0 && document.getElementById('room').value.length > 0) { document.getElementById('overlayId').value = url() + '/overlay/' + document.getElementById('room').value + ':' + localStorage.getItem('userId') + '?scale=10&clearAfter=30'; @@ -61,14 +72,7 @@ function start(event = undefined) { localStorage.setItem(document.getElementById('name').value + '-started', "true") - let httpRequest = new XMLHttpRequest(); - httpRequest.open('POST', url() + '/dice/' + document.getElementById('room').value + '/register') - httpRequest.setRequestHeader('Content-Type', 'application/json') - httpRequest.send(JSON.stringify({ - name: document.getElementById('name').value, - overlay: document.getElementById('overlayId').value, - id: document.getElementById('room').value + ':' + localStorage.getItem('userId') - })) + register(); if (document.getElementById('gm').checked) { document.getElementById('resultSwitch').checked = true; document.getElementById('resultFrame').src = document.getElementById('resultsId').value; @@ -98,18 +102,21 @@ function start(event = undefined) { newOverlay.appendChild(newInput); overlays.appendChild(newOverlay); - let dice = document.createElement('iframe'); - dice.id = data.id + '-diceFrame' - dice.style.width = "50%"; - dice.style.height = "100%"; - dice.style.overflow = "hidden"; - dice.style.border = "0"; - dice.style.zIndex = "4"; - dice.style.position = "absolute"; - dice.style.top = "0"; - dice.style.left = "50%"; - dice.src = data.overlay; - document.getElementById('results-dice').appendChild(dice) + if (!document.getElementById(data.id + '-diceFrame')) { + let dice = document.createElement('iframe'); + dice.id = data.id + '-diceFrame' + dice.style.width = "50%"; + dice.style.height = "100%"; + dice.style.overflow = "hidden"; + dice.style.border = "0"; + dice.style.zIndex = "4"; + dice.style.position = "absolute"; + dice.style.top = "0"; + dice.style.left = "50%"; + dice.src = data.overlay; + document.getElementById('results-dice').appendChild(dice) + + } } configurePopover(); @@ -125,6 +132,7 @@ function rollEasy(dice) { function roll(event) { if ((!event || event.keyCode === 13) && document.getElementById('command').value?.length > 0) { + register() let httpRequest = new XMLHttpRequest(); httpRequest.open('POST', url() + '/dice/' + document.getElementById('room').value + ':' + localStorage.getItem(`userId`)) httpRequest.setRequestHeader('Content-Type', 'application/json') @@ -207,11 +215,7 @@ document.addEventListener("DOMContentLoaded", async () => { }) document.getElementById('resultDiceSwitch').addEventListener('change', function () { - if (!this.checked) { - document.getElementById('results-dice').hidden = true - } else { - document.getElementById('results-dice').hidden = false - } + document.getElementById('results-dice').hidden = !this.checked; }) document.getElementById('chatOverlayLink').href = url() + '/chatoverlay' diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index 10b289a..f599358 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -202,11 +202,8 @@

How-To