summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2023-12-24 00:36:43 +0100
committerTor Andersson <tor@ccxvii.net>2023-12-24 00:52:21 +0100
commit3e9bc21e757fc13cc8d66cea1d5dcf813f27b4f0 (patch)
tree48bc5bdb3a405c83981c4a5924fbd7b6a4e95318
parentae5ce79bb58b46d04d79134ca8fe094085496dd8 (diff)
downloadserver-3e9bc21e757fc13cc8d66cea1d5dcf813f27b4f0.tar.gz
Create resign menu automatically.
-rw-r--r--public/common/client.js30
1 files changed, 20 insertions, 10 deletions
diff --git a/public/common/client.js b/public/common/client.js
index 87dc698..6de38fe 100644
--- a/public/common/client.js
+++ b/public/common/client.js
@@ -506,14 +506,15 @@ function connect_play() {
case "players":
player = arg[0]
+ init_player_names(arg[1])
document.body.classList.add(player.replace(/\W/g, "_"))
if (player !== "Observer") {
init_chat()
init_notepad()
+ add_resign_menu()
} else {
remove_resign_menu()
}
- init_player_names(arg[1])
break
case "presence":
@@ -713,11 +714,6 @@ function send_query(q, param) {
send_message("query", [ q, param ])
}
-function confirm_resign() {
- if (window.confirm("Are you sure that you want to resign?"))
- send_message("resign")
-}
-
function send_save() {
send_message("save")
}
@@ -736,6 +732,24 @@ function init_replay() {
/* MAIN MENU */
+function confirm_resign() {
+ if (window.confirm("Are you sure that you want to resign?"))
+ send_message("resign")
+}
+
+function add_resign_menu() {
+ if (Object.keys(roles).length <= 2) {
+ let popup = document.querySelector("#toolbar details menu")
+ popup.insertAdjacentHTML("beforeend", '<li class="resign separator">')
+ popup.insertAdjacentHTML("beforeend", '<li class="resign" onclick="confirm_resign()">Resign')
+ }
+}
+
+function remove_resign_menu() {
+ for (let e of document.querySelectorAll(".resign"))
+ e.remove()
+}
+
function add_icon_button(where, id, img, fn) {
let button = document.getElementById(id)
if (!button) {
@@ -751,10 +765,6 @@ function add_icon_button(where, id, img, fn) {
return button
}
-function remove_resign_menu() {
- document.querySelectorAll(".resign").forEach(x => x.remove())
-}
-
/* avoid margin collapse at bottom of main */
document.querySelector("main").insertAdjacentHTML("beforeend", "<div style='height:1px'></div>")