michalrus / anki-simple-cloze-overlapper

Simple Cloze Overlapper template for Anki 2.1 (probably any version, as it's JavaScript-only)
76 stars 13 forks source link

fix: render on document.body.className changes #17

Closed gregorias closed 4 months ago

gregorias commented 4 months ago

In https://github.com/gregorias/anki-code-highlighter/issues/86, we’ve discovered that Simple Cloze Overlapper renders a blank screen. I’ve discovered that’s due to the plugin’s script not working with an up-to-date class list (https://forums.ankiweb.net/t/card-card-classes-only-injected-separately-now/27387)

This commit adds an observer to className to address the issue.

michalrus commented 4 months ago

Awesome! Thank you :)

nihil-admirari commented 4 months ago

One can wait for Anki to update the class list by appending a callback to onUpdateHook array (the call chain is _showQuestion() -> _updateQA() -> onUpdateHook).

There are complications on other Anki platforms, e.g. on AnkiWeb the hooks are completely absent, and class list is taken from #qa_box and not from <body> (MutationObserver doesn't show #qa_box class list to be changing though).

See https://github.com/nihil-admirari/modern-cloze-overlapper/blob/master/_cloze-overlapper-loader.js for the details.