replace user buzzer with big red button
This commit is contained in:
parent
df4da0997a
commit
e197c2364f
3 changed files with 111 additions and 34 deletions
|
|
@ -73,8 +73,20 @@ ul {
|
||||||
align-items: center;
|
align-items: center;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 90%;
|
height: 90%;
|
||||||
|
flex-direction: column;
|
||||||
|
text-align: center;
|
||||||
}
|
}
|
||||||
#active {
|
#buzzbutton {
|
||||||
color: red;
|
width: 200px;
|
||||||
|
height: 200px;
|
||||||
|
background-color: red;
|
||||||
|
border-radius: 100%;
|
||||||
|
font-size: 1em;
|
||||||
|
}
|
||||||
|
#buzzbutton .active {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
.inactive {
|
||||||
|
color: #c00;
|
||||||
|
font-size: 2em;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
Error:
|
Error:
|
||||||
<code></code>
|
<code></code>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="points-admin" class="admin-only">
|
<div id="points-admin" class="admin-only">
|
||||||
<h2>Admin</h2>
|
<h2>Admin</h2>
|
||||||
<div><a href="monitor.html" onclick="this.href='monitor.html'+location.hash">Monitor</a></div>
|
<div><a href="monitor.html" onclick="this.href='monitor.html'+location.hash">Monitor</a></div>
|
||||||
|
|
@ -45,24 +46,37 @@
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="info">
|
|
||||||
<label class="myname player-only"
|
<div id="userinfo" class="player-only">
|
||||||
|
<label
|
||||||
>You:
|
>You:
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
name="username"
|
name="username"
|
||||||
id="username"
|
id="username"
|
||||||
placeholder="Please put your name here ..."
|
placeholder="Please put your name here ..."
|
||||||
/></label>
|
data-onchange="q('#set-name').disabled = false"
|
||||||
|
/><button id="set-name" data-onclick="
|
||||||
|
set_name(named.username.value)
|
||||||
|
target.disabled = true
|
||||||
|
">set name</button>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="info" class="admin-only">
|
||||||
<h2>All Players</h2>
|
<h2>All Players</h2>
|
||||||
<ul class="players">
|
<ul class="players">
|
||||||
<!-- players (see template#player) will be inserted here -->
|
<!-- players (see template#player) will be inserted here -->
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="buzzbox" class="player-only">
|
<div id="buzzbox" class="player-only">
|
||||||
<p id="active">BZZZZZ!</p>
|
<button id="buzzbutton">
|
||||||
<p id="ready">Press <strong id="bkey">{key.name}</strong> to activate buzzer.</p>
|
<div class="ready">Press the big red button</div>
|
||||||
<p id="inactive">Please focus the window to allow the buzzer to work.</p>
|
<div class="active">BZZZZZ!</div>
|
||||||
|
</button>
|
||||||
|
<p>or press <strong id="bkey">{key.name}</strong> to activate buzzer.</p>
|
||||||
|
<p class="inactive">Please focus the window to allow the buzzer to work.</p>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|
|
||||||
103
public/buzzer.js
103
public/buzzer.js
|
|
@ -35,12 +35,12 @@ let conn,
|
||||||
clients = []
|
clients = []
|
||||||
|
|
||||||
function hide(e) {
|
function hide(e) {
|
||||||
e = isString(e) ? q(`#${e}`) : e
|
e = isString(e) ? q(e) : e
|
||||||
e.style.display = "none"
|
e.style.display = "none"
|
||||||
}
|
}
|
||||||
|
|
||||||
function show(e) {
|
function show(e) {
|
||||||
e = isString(e) ? q(`#${e}`) : e
|
e = isString(e) ? q(e) : e
|
||||||
e.style.display = "block"
|
e.style.display = "block"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -114,50 +114,101 @@ function highlight(client_id, until_ns) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function setup_ui() {
|
function setup_ui() {
|
||||||
|
const buzzbutton = q("#buzzbutton")
|
||||||
|
const username = q("#username")
|
||||||
|
|
||||||
on("focus", (event) => {
|
on("focus", (event) => {
|
||||||
hide("active")
|
hide(".inactive")
|
||||||
hide("inactive")
|
|
||||||
show("ready")
|
|
||||||
})
|
})
|
||||||
on("blur", (event) => {
|
on("blur", (event) => {
|
||||||
hide("active")
|
show(".inactive")
|
||||||
show("inactive")
|
|
||||||
hide("ready")
|
|
||||||
})
|
})
|
||||||
if (document.hasFocus()) {
|
if (document.hasFocus()) {
|
||||||
hide("inactive")
|
hide(".inactive")
|
||||||
} else {
|
}
|
||||||
hide("ready")
|
|
||||||
|
let buzzing = false
|
||||||
|
|
||||||
|
function buzz() {
|
||||||
|
if (!buzzing) {
|
||||||
|
buzzing = true
|
||||||
|
conn.send("buzz", conn.servertime_now_ns())
|
||||||
|
show(".active")
|
||||||
|
hide(".ready")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function unbuzz() {
|
||||||
|
buzzing = false
|
||||||
|
hide(".active")
|
||||||
|
show(".ready")
|
||||||
}
|
}
|
||||||
|
|
||||||
q("#bkey").textContent = buzzer_key.name
|
q("#bkey").textContent = buzzer_key.name
|
||||||
let buzzing = false
|
|
||||||
on("keydown", (event) => {
|
on("keydown", (event) => {
|
||||||
if (!buzzing && event.keyCode === buzzer_key.code) {
|
if (event.target === username) {
|
||||||
buzzing = true
|
return
|
||||||
conn.send("buzz", conn.servertime_now_ns())
|
}
|
||||||
show("active")
|
if (event.keyCode === buzzer_key.code) {
|
||||||
hide("ready")
|
buzz()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
on("keyup", (event) => {
|
on("keyup", (event) => {
|
||||||
|
if (event.target === username) {
|
||||||
|
return
|
||||||
|
}
|
||||||
if (event.keyCode === buzzer_key.code) {
|
if (event.keyCode === buzzer_key.code) {
|
||||||
buzzing = false
|
unbuzz()
|
||||||
hide("active")
|
|
||||||
show("ready")
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const username_el = q("#username")
|
on(
|
||||||
|
"mousedown",
|
||||||
|
(event) => {
|
||||||
|
buzz()
|
||||||
|
},
|
||||||
|
{ target: buzzbutton },
|
||||||
|
)
|
||||||
|
on(
|
||||||
|
"mouseup",
|
||||||
|
(event) => {
|
||||||
|
unbuzz()
|
||||||
|
},
|
||||||
|
{ target: buzzbutton },
|
||||||
|
)
|
||||||
|
on(
|
||||||
|
"mouseleave",
|
||||||
|
(event) => {
|
||||||
|
unbuzz()
|
||||||
|
},
|
||||||
|
{ target: buzzbutton },
|
||||||
|
)
|
||||||
|
|
||||||
|
const named = Object.fromEntries(
|
||||||
|
Array.from(document.querySelectorAll("[name]")).map((el) => [el.name, el]),
|
||||||
|
)
|
||||||
if (storage["my_name"]) {
|
if (storage["my_name"]) {
|
||||||
username_el.value = storage["my_name"]
|
username.value = storage["my_name"]
|
||||||
}
|
}
|
||||||
on(
|
on(
|
||||||
"change",
|
"change",
|
||||||
(event) => {
|
({ target }) => {
|
||||||
set_name(event.target.value)
|
if (!target.dataset.onchange) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
eval(`;{${target.dataset.onchange}};`)
|
||||||
},
|
},
|
||||||
{ target: username_el },
|
{ target: q("#userinfo") },
|
||||||
|
)
|
||||||
|
on(
|
||||||
|
"click",
|
||||||
|
({ target }) => {
|
||||||
|
if (!target.dataset.onclick) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
eval(`;{${target.dataset.onclick}};`)
|
||||||
|
},
|
||||||
|
{ target: q("#userinfo") },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -290,7 +341,7 @@ function setup_ws() {
|
||||||
storage["session_key"] = session_key.key
|
storage["session_key"] = session_key.key
|
||||||
disable_player_ui()
|
disable_player_ui()
|
||||||
enable_admin_ui()
|
enable_admin_ui()
|
||||||
set_name('Admin')
|
set_name("Admin")
|
||||||
})
|
})
|
||||||
conn.on("control", ({ value }) => {
|
conn.on("control", ({ value }) => {
|
||||||
// ignore
|
// ignore
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue