[Userscript] Forum: IME2Furigana

First a warning: this script is barely tested, so it might fail sometimes (or always). Please post cases where it fails.

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 漢字(かんじ).
    The markup is the same as in the Easy Furigana userscript by @Kumirei.

  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 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:

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:

Version history

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

To the post without details about this patch

v 1.4 (Furigana bugfix)

To the post without details about this patch

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

To the post without 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

24 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 明日.

3 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.

1 Like

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 https://www.w3.org/International/articles/ruby/markup.en 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.