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