kanji stroke order font script for anki

Index » Learning resources

  • 1
 
Irwin1138
New member
From: Israel
Registered: 2009-11-17
Posts: 3

Hi there, I thought it would be nice to share a little script I wrote. I wanted a convenient way to get the stroke order info right there when I'm doing reps, without the hassle of copy-pasting to the browser or (oh lord) searching the RTK book.

I could just replace the default Arial font with it but I like Arial more.

You need to get the KanjiStrokeOrders font and install it in your system. I use Windows dunno how to do it in CunniLinux.

You just hover the cursor over the kanji and it changes the font showing you the stroke order.

Here is the script:

Code:

<script language="JavaScript">
function toggleFont()
{
  var _font = document.getElementsByTagName('span')[0].style.fontFamily;
  if(_font != 'KanjiStrokeOrders') {
    document.getElementsByTagName('span')[0].style.fontFamily = 'KanjiStrokeOrders';
  }
  else {
    document.getElementsByTagName('span')[0].style.fontFamily = 'Arial'; //whatever font you want
  }
}
</script>

You just copy it to the question field somewhere.

And instead if {{Kanji}} in the same question field place this:

Code:

<a onmouseover="toggleFont();" onmouseout="toggleFont();">{{Kanji}}</a>

That's it!

Oh, and if Anki was open during the font installation you should probably restart it.

Reply #2 - 2011 March 29, 1:29 pm
AdachiFan
New member
Registered: 2011-03-29
Posts: 4

Does anyone know how to get this to work? I like the concept but can't seem to make it work properly. Kanji text appears to be hardwired to whatever font is set in the 'Fields' tab of the card layout.

jbudding
Member
From: Las Vegas, Nevada
Registered: 2007-03-24
Posts: 49

I copied the script exactly into the card layout tab above the line for {{Kanji}}, changed the arial to ms mincho and then pasted the mouseover script over the {{Kanji}} and it works like a charm!  I wanted something like this for a while and was thing of pasting in the strokeorder url for each kanji from the wwwjdic but this is much cooler (and way easier!) and doesn't need a web connection. Thanks so much Irwin1138!

Here is my exact card layout for the Question side:

<script language="JavaScript">
function toggleFont()
{
  var _font = document.getElementsByTagName('span')[0].style.fontFamily;
  if(_font != 'KanjiStrokeOrders') {
    document.getElementsByTagName('span')[0].style.fontFamily = 'KanjiStrokeOrders';
  }
  else {
    document.getElementsByTagName('span')[0].style.fontFamily = 'MS MINCHO'; //whatever font you want
  }
}
</script>
<a onmouseover="toggleFont();" onmouseout="toggleFont();">{{Kanji}}</a>
画数: {{Stroke count}}, Nr: {{Heisig number}}

Advertising (register and sign in to hide this)
JapanesePod101
Sponsor
 
Reply #4 - 2011 March 30, 1:07 pm
Shadeless
Member
Registered: 2010-05-25
Posts: 39

Thanks Irwin1138 & jbudding, I finally got it to work.. it's awesome big_smile

Is there a way for font to change size on hover though?

Last edited by Shadeless (2011 March 30, 1:10 pm)

Reply #5 - 2011 March 30, 1:51 pm
loonytik
Member
From: netherlands
Registered: 2010-03-27
Posts: 63

I have the same problem as AdachiFan the Kanji seems to be hardwired and it doesnt change. Its font is Arial. But it just won't change. However the keyword does change from font haha. I use the premade rtk 1+3 deck downloadable from the sahred deck section..

Reply #6 - 2011 March 30, 2:39 pm
amelie
New member
From: France
Registered: 2009-07-06
Posts: 3

Hello!
Jbudding, can you post a image of this script in anki please?

I'm trying to get a working stroke order font in a deck but can't do it. (see the post "Super Heisig anki deck")

Last edited by amelie (2011 March 30, 2:41 pm)

Reply #7 - 2011 March 30, 2:47 pm
van_fanel
New member
Registered: 2011-02-21
Posts: 1

I would like to add this feature to the answercard. I have no experience in html-programming. So, how do i get this done?

Gruß Van

Reply #8 - 2011 March 30, 9:32 pm
Eadwyn
Member
From: Kirkland - WA - USA
Registered: 2011-03-24
Posts: 26

EDIT: Forgot to thank Irwin1138!

loonytik wrote:

I have the same problem as AdachiFan the Kanji seems to be hardwired and it doesnt change. Its font is Arial. But it just won't change. However the keyword does change from font haha. I use the premade rtk 1+3 deck downloadable from the sahred deck section..

NOTE: This is for the pre-made RTK 1+3 deck:

It's because in the script it is changing the 1st span tag, which in your case is the keyword.  I modified it slightly to modify the tag with the name attribute of "kanji" to prevent the location of the tags from mattering.  Try using this for the Question field:

<span style="font-family: Arial; font-size: 20px; color: #000000; white-space: pre-wrap;"><a href="http://kanji.koohii.com/study/?framenum={{text:Heisig number}}">{{{Keyword}}}</a</br></br>{{{Story}}}</span>

And this for the answer field:

<script language="JavaScript">
function toggleFont()
{
  var _font = document.getElementsByName('kanji')[0].style.fontFamily;
  if(_font != 'KanjiStrokeOrders') {
    document.getElementsByName('kanji')[0].style.fontFamily = 'KanjiStrokeOrders';
  }
  else {
    document.getElementsByName('kanji')[0].style.fontFamily = 'MS Mincho';
  }
}
</script>

<div align="center" name="kanji" style="font-family:MS Mincho; font-size:150px;"><a onmouseover="toggleFont();" onmouseout="toggleFont();">{{{Kanji}}}</a></div>
<div align="right">画数: {{Stroke count}}, Nr: {{Heisig number}}</div>

EDIT#2: The {{Kanji}} needs to be changed to {{{Kanji}}}.  If it isn't changed to include the 3rd set of squiggly brackets, the font will not change.

Last edited by Eadwyn (2011 March 30, 11:21 pm)

Eadwyn
Member
From: Kirkland - WA - USA
Registered: 2011-03-24
Posts: 26

After seeing the font changing script, I came up with the idea to have the story text hidden by default unless the mouse is hovering over the keyword.

For those with the pre-made RTK 1+3 deck, put this in the Question field (If not using this deck, then modify your deck by looking at this example):

<script type="text/javascript">
  function showStory()
  {
    var _storyHidden = document.getElementsByName('story')[0].style.visibility;
    if (_storyHidden == 'hidden') {
      document.getElementsByName('story')[0].style.visibility = 'visible';
    } else {
      document.getElementsByName('story')[0].style.visibility = 'hidden';
    }
  }
</script>

<span style="font-family: Arial; font-size: 20px; color: #000000; white-space: pre-wrap;">
<a href="http://kanji.koohii.com/study/?framenum={{text:Heisig number}}" onmouseover="showStory();" onmouseout="showStory();">{{{Keyword}}}</a>
</span>
<br/>
<br/>
<div name="story" style="font-family: Arial; font-size: 20px; color: #000000; white-space: pre-wrap;visibility:hidden;">{{{Story}}}</div>

Reply #10 - 2011 March 31, 3:03 am
loonytik
Member
From: netherlands
Registered: 2010-03-27
Posts: 63

Thanks allot Eadwyn big_smile! works perfectly now smile

Reply #11 - 2011 March 31, 6:54 pm
AdachiFan
New member
Registered: 2011-03-29
Posts: 4

Eadwyn, you're a legend. Great stuff. Elegant solution because now it doesn't matter where the kanji is displayed. Cheers to Irwin 1138, of course, for originally posting the script of course though. Much appreciated. Got my decks pretty much perfect now.

Is it possible to get the kanji number/stroke in a static position though? It's ever so slightly jarring having them move when you mouseover and the stroke order is displayed. I see that the stroke order font takes up more space but if the other fields were in an absolute position and didn't overlap, it shouldn't matter right?

Reply #12 - 2011 March 31, 7:54 pm
Eadwyn
Member
From: Kirkland - WA - USA
Registered: 2011-03-24
Posts: 26

AdachiFan wrote:

Eadwyn, you're a legend. Great stuff. Elegant solution because now it doesn't matter where the kanji is displayed. Cheers to Irwin 1138, of course, for originally posting the script of course though. Much appreciated. Got my decks pretty much perfect now.

Is it possible to get the kanji number/stroke in a static position though? It's ever so slightly jarring having them move when you mouseover and the stroke order is displayed. I see that the stroke order font takes up more space but if the other fields were in an absolute position and didn't overlap, it shouldn't matter right?

Here's a quick solution I came up with:

<script language="JavaScript">
function toggleFont()
{
  var _font = document.getElementsByName('kanji')[0].style.fontFamily;
  if(_font != 'KanjiStrokeOrders') {
    document.getElementsByName('kanji')[0].style.fontFamily = 'KanjiStrokeOrders';
    document.getElementsByName('kanji')[0].style.fontSize = '112px';
  }
  else {
    document.getElementsByName('kanji')[0].style.fontFamily = 'MS Mincho';
    document.getElementsByName('kanji')[0].style.fontSize = '150px';
  }
}
</script>

<div align="center" name="kanji" style="font-family:MS Mincho; font-size:150px;"><a onmouseover="toggleFont();" onmouseout="toggleFont();">{{{Kanji}}}</a></div>
<div align="right">画数: {{Stroke count}}, Nr: {{Heisig number}}</div>



This will work if using the MS Mincho font for the Kanji.

Reply #13 - 2011 April 01, 6:09 pm
AdachiFan
New member
Registered: 2011-03-29
Posts: 4

Good man smile. Thanks a lot. I should really learn javascript etc. at some point. After Japanese though tongue

Reply #14 - 2011 May 27, 7:22 am
Irwin1138
New member
From: Israel
Registered: 2009-11-17
Posts: 3

Wow, someone did find this script helpful! I'm glad I found time to post it here smile

Reply #15 - 2012 March 09, 3:04 pm
truando
Member
From: I wish it was Japan
Registered: 2010-07-19
Posts: 363
Website

It's fantastic, Irwin1138, thank you so much! Also Eadwin!!

Reply #16 - 2012 August 08, 1:03 am
Irwin1138
New member
From: Israel
Registered: 2009-11-17
Posts: 3

For anki2 I had to modify the whole thing to make it work, with css and stuff. Here is the current setup for my RTK1-3 cards:

Front template:

<a href="http://kanji.koohii.com/study/?framenum={{text:Heisig number}}">{{Heisig number}}</a>
<div class=kanji>{{Kanji}}</div>
<div>{{Japanese Keyword}}</div>
<a href="#" onclick="document.getElementById('story').style.display='block';return false;">
Show Story
</a>

<div id="story">
{{Story}}<br />
-------------------<br />
{{Story 2}}
</div>





Styling:

.card {
font-family: arial;
font-size: 20px;
text-align: center;
color: black;
background-color: white;
}

.card1 {
font-family: arial;
font-size: 20px;
text-align: center;
color: black;
background-color: white;
}

div.kanji {
font-size: 150px;
}

div.keyword {
margin-top: 20px;
}

#left {
float: left;
}

#clear {
clear: both;
}

div.kanji:hover {
font-family: KanjiStrokeOrders;
font-size: 130px;
}

div#story {
display: none;
}



Back template:

<a href="http://kanji.koohii.com/study/?framenum={{text:Heisig number}}">{{Heisig number}}</a><br />
<div id=left class=kanji>{{Kanji}}</div>
<div class=keyword>{{Keyword}}</div>
<div>{{Japanese Keyword}}</div>
<div>{{Keyword Hiragana}}</div>
<div>{{Sentence}}</div>
<div id=clear></div>
<a href="#" onclick="document.getElementById('story').style.display='block';return false;">
Show Story
</a>

<div id="story">
{{Story}}<br />
-------------------<br />
{{Story 2}}
</div>



Here is how it all looks:
http://i50.tinypic.com/24enmvt.png

Note: the little kanji under the big one is for the cases where the japanese keyword is a compound or includes hiragana. Makes a good hint.
Oh and if you hover the kanji it still shows stroke order smile

A little explanation. I have added japanese keywords with example sentences to my deck (somewhere on the forum was a topic about jrtk, I took the data from there). Since you most probably don't have these, you should just remove the fields in the html with japanese keywords and such.

Also, my deck includes RTK1, RTK3 and the RTK1 supplement. For about 2000 there is a japanese keyword with reading and an example sentence. For each kanji there are 2 stories. If anyone is interested I can export it so others can use it.

Last edited by Irwin1138 (2012 August 08, 1:05 am)

  • 1