add admin ability to double card values

This commit is contained in:
ducklet 2021-03-02 20:08:28 +01:00
parent a4b0297c3f
commit 81ee2200fb
5 changed files with 22 additions and 1 deletions

View file

@ -59,6 +59,10 @@
></textarea>
</label>
</div>
<div>
<label
>double:
<button data-onclick="conn.send('control', {action: 'double'})">double</button>
</label>
</div>
</div>

View file

@ -1,5 +1,7 @@
"use strict"
import { qs } from "./shared.js"
function setup() {
let highlighted
document.addEventListener("click", (event) => {
@ -18,6 +20,18 @@ function setup() {
highlighted = card
card.classList.add("highlight")
})
window.addEventListener("message", ({ data }) => {
if (data !== "double") {
return
}
for (let card of qs(".card")) {
if (card.classList.contains("cat")) {
continue
}
card.textContent = parseInt(card.textContent) * 2
}
})
}
setup()

View file

@ -6,7 +6,7 @@
<div id="players">
<!-- players (see template#player) will be inserted here -->
</div>
<iframe src="matrix.html"></iframe>
<iframe id="board" src="matrix.html"></iframe>
<div id="text-overlay" class="hidden"></div>
</div>
</body>

View file

@ -174,6 +174,8 @@ function setup_ws() {
} else if (action === "sound" && args.sound) {
const { client_id, sound } = args
sounds[client_id] = new Audio(`sounds/${sound}.mp3`)
} else if (action === "double") {
q("#board").contentWindow.postMessage("double", "*")
}
},
)

View file

@ -15,6 +15,7 @@ export function isEmpty(x) {
}
export const q = (selector, root = document) => root.querySelector(selector)
export const qs = (selector, root = document) => root.querySelectorAll(selector)
const _evlisteners = {}