Replace use of window.postMessage in card info (#3646)

* Use anki.updateCard instead of window.onmessage in card-info

* Make card-info placeholder text grey

---------

Co-authored-by: Abdo <abdo@abdnh.net>
This commit is contained in:
llama 2024-12-18 16:32:07 +08:00 committed by GitHub
parent 474dbc2812
commit b061da73d3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 9 additions and 7 deletions

View file

@ -73,7 +73,7 @@ class CardInfoDialog(QDialog):
card_id = None
assert self.web is not None
self.web.eval(f"window.postMessage('{card_id}');")
self.web.eval(f"anki.updateCard('{card_id}');")
def reject(self) -> None:
if self._on_close:

View file

@ -15,5 +15,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: grey;
}
</style>

View file

@ -13,12 +13,13 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
const showRevlog = $page.url.searchParams.get("revlog") !== "0";
function updateCardId(evt: MessageEvent) {
goto(`/card-info/${evt.data}`);
}
globalThis.anki ||= {};
globalThis.anki.updateCard = async (card_id: string): Promise<void> => {
const path = `/card-info/${card_id}`;
return goto(path).catch(() => {
window.location.href = path;
});
};
</script>
<!-- used by CardInfoDialog.update_card -->
<svelte:window on:message={updateCardId} />
<CardInfo stats={data.info} {showRevlog} />