[Userscript] Forum: IME2Furigana

This is a third-party script and is not created by the WaniKani team. By using this, you understand that it can stop working at any time or be discontinued indefinitely.

General script installation instructions
IME2Furigana

What does it do?

The script targets the reply textbox of the WaniKani forum. It adds two functionalities:

  1. Furigana markup
    Writing <.漢字>[かんじ] results in 漢字(かんじ), while writing <.漢字>{かんじ} results in 漢字(かんじ).

  2. IME input to furigana markup
    The script takes what you have entered in your IME and converts it into furigana markup.

Example: you write ふりがな, then select 振り仮名 from the list in your IME, and the result is <.振>[ふ]り<.仮名>[がな] which gets displayed as ()仮名(がな).

This also means that you have to write the whole word before selecting an entry from the IME. If you stop at ふりが and then select 振り仮名 from the IME suggestions, you will get ()仮名().

Furthermore this script is unaware of any kanji readings, so it is not able to display 四月 as がつ (correctly mapped し to 四 and がつ to 月) but only as 四月(しがつ). But it seems that several people prefer it like this anyway.

Script modes

This script adds a button (labeled “F”) to the reply box in the WaniKani forum. Clicking this button (or using Ctrl+Shift+F) switches between 3 modes:

  • off: both script functionalities disabled
  • on: furigana is added as soon as an entry has been chosen in the IME
  • blur: same as on, but the furigana is marked as spoiler - so it is blurred until clicked (example: ()仮名(がな))

How to use it:

Make sure that you have IME2Furigana enabled (click the F button if it is not enabled):

Type the whole word/phrase/sentence into your IME (don’t use prediction before you have fully typed what will be used as furigana):

After letting the IME convert it to kanji, it will be replaced with furigana markup:


(Since this screenshot was taken, the furigana markup was changed to include a dot to avoid conflicts with HTML tags.)

Converting ruby markup to furigana markup

As soon as ruby markup is detected in the input box (maybe because you are quoting another post that used ruby, or you pasted ruby markup from another page, or you are editing one of your own posts that used ruby markup), IME2Furigana offers to convert it into furigana markup:

After accepting by clicking the check mark, the long ruby markup is replaced with the more compact furigana markup in the input box:


(Since this screenshot was taken, the furigana markup was changed to include a dot to avoid conflicts with HTML tags.)

Warnings

  • There is a known issue due to a Discourse update: the Discourse formatting tools (e.g. Ctrl+i or clicking the “Emphasis” button with some text after the first furigana markup occurrence selected will produce incorrect results.
  • The furigana markup was changed to include a dot to distinguish it from HTML tags, to prevent the conversion from being applied in unintended places. But it might still be advisable to double-check for misconversions before saving a post – especially when editing a long wiki post. If the post should not contain any furigana, it might be best to turn off the F button, or make sure that there is no blue indicator in the F button (the blue line below the F button signifies, that IME2Furigana has found text that looks like furigana markup).

Version history

v 1.8 (Fallback method)
  • Added fallback method if original method does not work
  • F button now indicates if IME2Furigana tampers with your input
  • Added hotkey for changing the mode
  • You can now undo the automatic furigana markup

To the post with details about this patch

v 1.7 (Bugfixes)

To the post with details about this patch

v 1.6 (Script mode initialized to "on" + 2 bugfixes)

To the post with details about this patch

v 1.5 (Bugfix for browsers not supporting RegExp negative lookbehind)

To the post with details about this patch

v 1.4 (Furigana bugfix)

To the post with details about this patch

v 1.3 (Added setting for unprompted ruby to furigana markup conversion)

To the post with details about this patch

v 1.2 (Ruby to furigana markup feature)

To the post with details about this patch

v 1.1 (fixed typo)

To the post with details about this patch

v 1.0 (Added furigana markup functionality)

Added furigana markup functionality
IME input gets converted to furigana markup
Button state is now persistent
To the post with details about this patch

v 0.3 (button state bugfix)

To the post without details about this patch

v 0.2 (rp tags)

Now also creates <rp> tags
To the post with details about this patch

41 Likes

Nice, sounds cool!

Later this year I’m planning to build an actual Discourse plugin to simplify adding furigana. But I need a new computer first. :confounded:

7 Likes

ためしている
(didnt see the f)

1 Like

Right, I should have added an image to my first post to show the location of the button that activates this script’s functionality. Fixed.

1 Like

すごい!!!

亜梨画東御剤升ありがとうございます

4 Likes

便利べんりそうですね。
Also definitely nice because I just made a post where I typed this by hand, and that would get annoying fast.

2 Likes

Oh, but you have used the rp tags to add brackets to the furigana in this other post, so it looks much nicer when quoted. I have updated my script so that it also adds rp tags.

Version 0.2 now also returns the focus back to the textbox after clicking the “F” button so that you can immediately continue typing without having to click into the textbox first.

1 Like

Discourse has on their very long to-do list to eventually fix the quoting for ruby tags so it will include them in the quoted text. But I guess the rp tags are still useful (even in the long run) when copying between sites.

2 Likes

このスクリプトは素晴(すば)らしいです。

4 Likes

ルビーテキストが好きI like ruby text :slight_smile:

3 Likes

Isn’t this how it’s usually written anyway?


Neat script, it’s better than my script which converts <kanji>[furigana] into ruby


Bug report: The script remembers that I turned it on, but the button is says off when I start a new post (until I click it again and it says blur)

2 Likes

Generally the furigana should be above the specific kanji it’s actually associated with. The exception is when the reading of the word has no association with the individual kanji, like with 明日.

4 Likes

In my experience they seem to center the furigana on the word whenever the reading is longer than maybe 3 or 4 kana, for a word with two kanji

I actually just saw furigana in a physical book the other day that added whitespace similar to the browser to put the furigana above just the correct kanji. But I’ve seen what you said as well for long readings. I still think that’s bad practice when the reading only has one or two characters and would fit above the correct kanji though.

2 Likes

Thanks for the report, I have fixed it (version 0.3).

Regarding the positioning of the furigana, I think that a clear mapping where possible would be preferable. But as far as I know most webbrowsers except for firefox don’t support ruby well enough to do this. I’ve read through Ruby Markup a while ago and the browser support doesn’t look too good.

2 Likes

Kinda think something like 小林こばやし looks rather better than ばやし. Also, fewer tags needed.

2 Likes

I think the same holds for even 四月(しがつ) and がつ

3 Likes

Bit of a strange question, is it possible to make this available for any discourse forum? I would love to also be able to use this on BunPro for example.

I think it should work if you just add
// @match https://community.bunpro.jp/*
after or before
// @match https://community.wanikani.com/*

That would work, I just was wondering if there was a way to detect whether you are using a discourse forum, or if that would require a complex script.