mirror of
https://github.com/ankitects/anki.git
synced 2025-11-06 12:47:11 -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 = "/";
|
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;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue