postParentMessage function

This commit is contained in:
Luc Mcgrady 2025-10-31 12:41:12 +00:00
parent b66a10ea26
commit 23babca417
No known key found for this signature in database
GPG key ID: 4F3D7A0B17CC3D9C

View file

@ -54,14 +54,22 @@ const base = document.createElement("base");
base.href = "/";
document.head.appendChild(base);
function postParentMessage(message: ReviewerRequest) {
window.parent.postMessage(
message,
"*",
);
}
function pycmd(cmd: string) {
const match = cmd.match(/play:(q|a):(\d+)/);
if (match) {
const [_, context, index] = match;
window.parent.postMessage(
{ type: "audio", answerSide: context == "a", index: parseInt(index) } satisfies ReviewerRequest,
"*",
);
postParentMessage({
type: "audio",
answerSide: context === "a",
index: parseInt(index),
});
}
}
globalThis.pycmd = pycmd;
@ -70,9 +78,8 @@ function _typeAnsPress() {
const elem = document.getElementById("typeans")! as HTMLInputElement;
let key = (window.event as KeyboardEvent).key;
key = key.length == 1 ? key : "";
window.parent.postMessage(
{ type: "typed", value: elem.value + key } satisfies ReviewerRequest,
"*",
postParentMessage(
{ type: "typed", value: elem.value + key },
);
}
globalThis._typeAnsPress = _typeAnsPress;