Hello! Long time Anki user, first time HTML/JS programmer here!
So, I’ve used the Domino Chinese deck when starting to learn Chinese, and it served me quite well for some time. Recently, since I’ve started learning new words and phrases, I wanted to make it easier to add new cards. The main drawback I felt with the deck was that the stroke order for new Hanzi had to be added by hand in the “Media” field, and so I did a little tinkering with the card by including the Hanzi Writer API, so that if the “Media” field is empty, it will draw it based on the “Hanzi” field. Here’s the code for the field:
<script>
var testhanzi = `{{Hanzi}}`;
var media = `{{Media}}`;
if (media.length==0){
for (var ind = 0; ind<testhanzi.length; ind++){
if (testhanzi[ind].match(/[\u3400-\u9FBF]/)){
var writer = HanziWriter.create('character-target-div', testhanzi[ind], {
width: 100,
height: 100,
padding: 5,
delayBetweenLoops: 3000,
strokeAnimationSpeed: 0.5,
delayBetweenStrokes: 100});
writer.loopCharacterAnimation();}
}}
else {
document.getElementById("character-target-div").innerHTML = media;
}
</script>
...
<div class=others>
<div id="character-target-div"></div>
</div>
The card works perfectly fine on my desktop (Windows 11, Anki 23.12.1), but I use mostly AnkiDroid with my Samsung tablet. There, it works fine in the card preview both with gifs in the “Media” field and with the auto drawing:
Preview with “Media” field:
Preview without “Media” field:
However, when reviewing the card, it doesn’t work with neither of them, showing only a blank space where the drawings were supposed to be:
I’ve done some programming for embedded software, but this is my first time tinkering with HTML and JS code. Any ideas on what’s going wrong with my card?
Thanks in advance!
Debug info:
AnkiDroid Version = 2.18.4 (f867da96b8304edaebd0361326316bc7514f8cde)
Backend Version = 0.1.38-anki24.04.1 (24.04.1 ccd9ca1a8309b80bcb50ddc5d99c7ce63440bce9)
Android Version = 14 (SDK 34)
ProductFlavor = play
Manufacturer = samsung
Model = SM-X610
Hardware = s5e8835
Webview User Agent = Mozilla/5.0 (Linux; Android 14; SM-X610 Build/UP1A.231005.007; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/127.0.6533.103 Safari/537.36
ACRA UUID = 54141355-3457-4985-bbea-4f7bf3b9af1e
FSRS Enabled = false
Crash Reports Enabled = true