diff --git a/src/components/hanzi-data/index.ts b/src/components/hanzi-data/index.ts index 44a360ab3684dabf114ca0fb918eed7d484536d3..4656ecfb660419458664e8a573d8ef2d356488bb 100644 --- a/src/components/hanzi-data/index.ts +++ b/src/components/hanzi-data/index.ts @@ -81,19 +81,17 @@ async function fetchNonBrowser (char: string): Promise<HanziData> { } /** - * Called from the JSONP script with the data. + * Callback for the JSONP scripts with the data. * * Raw JSON would not work with AnkiDroid, which does not support XHR/fetch, * but allows scripts. + * + * In AnkiDroid, every card gets a fresh window, but desktop and Anki Web + * preserved the callback from the last call. If window already contains a + * callback, it works to just overwrite the old callback here that is no longer + * needed. See #298 for details. */ if (!canAccessFilesystem) { - if (typeof window[jsonpCallbackFnName] !== 'undefined') { - throw new Error( - `Cannot register jsonp callback because window.${ - jsonpCallbackFnName - } is used` - ) - } window[jsonpCallbackFnName] = (char: string, data: HanziData) => { (jsonpWaiters.get(char) ?? []).forEach(w => { // careful: every consumer gets an identical object, don't modify