mirror of
https://github.com/ankitects/anki.git
synced 2025-11-06 04:37:22 -05:00
postParentMessage function
This commit is contained in:
parent
b66a10ea26
commit
23babca417
1 changed files with 14 additions and 7 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue