[Userscript] Forum: IME2Furigana

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.

I don’t think the URL can be used as an indicator if the webpage is a discouse forum, so I would have to inject the script into every webpage and then let it guess if the page is a discourse forum. The guess part is probably not a problem, but I don’t really like the idea that the script gets injected into every webpage you visit.

1 Like

Yeah, that sounds like a bit too much effort :sweat_smile:
I’ll just copy the @ match in the script instead. :yum:
Thanks!

It’s not really the effort but the privacy/security concerns that make me hesitate. In addition to that I also don’t like to add unnecessary workload to every webpage, even if this workload is negligible.

Maybe I’m also worrying too much. I’m 99% sure that my script could not be exploited by malicious code, even if it were to run on your online banking website, and who would even spend the effort to think up an exploit for a userscript that only a handful of people use?

I guess if you want (and don’t blame me if the 1% case happens :stuck_out_tongue:) I could make a second version of the script that runs on every webpage.

1 Like

I think the amount of effort on your end versus the amount of effort on my end is quite disproportional. So unless you really want to do it for yourself, don’t worry about it :blush:

1 Like

Version 1.0 patch-notes:

Added furigana markup functionality

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

The markup is the same as in the Easy Furigana userscript by @Kumirei.

I hope you never want to post the character sequence < something >[ something ]. If you come across such a situation, you have to disable IME2Furigana (with the F button).

IME input gets converted to furigana markup

Instead of immediately generating ruby markup and cluttering the input box with a monstrosity like <ruby lang = 'ja-JP'>振<rp>(</rp><rt>ふ</rt><rp>)</rp></ruby>り<ruby lang = 'ja-JP'>仮名<rp>(</rp><rt>がな</rt><rp>)</rp></ruby>, the IME input gets converted to furigana markup: <振>[ふ]り<仮名>[がな].

Button state is now persistent

The button state should now get shared across tabs and even sessions (unless you clear the browser data).

Important change: If you disable the IME2Furigana functionality with the F button, it does not only disable the IME input to furigana markup conversion, but also the furigana markup to ruby conversion.

If I broke something please also let me know.
Link to previous script version for downgrading in case version 1.0 doesn’t work/isn’t to your liking

4 Likes

Well then

I am learning a bunch of things from looking at the code of this script, thanks! I had no idea about the composition events, that’s great!

1 Like

Thanks! The hardest part for me was the injection into Discourse, because I don’t know anything about requireJS. That part was mostly trial and error, and I’m a bit worried that what I wrote there might break easily. So maybe it was a bit hasty of you to link to my script ^^ But thank you for having confidence in my script :slight_smile:

1 Like

I’m just an amateur scripter so it all looks like magic to me. I would never ever have thought of injecting. I think you mean Discourse, btw :eyes:

1 Like

Oops. You didn’t see a thing.

1 Like

It’s in the code too :eyes:

1 Like

image

Haha, nice :+1:

3 Likes

And it gets nicer :eyes: (what it looks like for me on that post)

bild

2 Likes

Is this already a bug report?

3 Likes

No, I think it’s fine(:+1: )

Here, I left a space so it didn’t become like this(:+1:)

3 Likes

Version 1.1 patch-notes:

Upgraded from Discord to Discourse

Fixed the typo/mistake where I wrote “Discord” instead of “Discourse”.

If I broke something in this patch I’d be very surprised.
Link to previous script version for downgrading in case you want to live the Discord life

3 Likes

I’ve been meaning to make my own markdown script, but hacking it into the post cooking is a pain. I have a working markdown plugin, which would be more useful across the board. But WaniKani’s Discourse plan doesn’t currently support custom plugins. So I’m trying to convert that plugin into a standalone script for the time being, but running it through the markdown engine without converting markdown unrelated to ruby is a pain.

Does overwriting w.require("pretty-text/engines/discourse-markdown-it").cook actually work? I wouldn’t think it would. I think if I run the whole post through that I’d still end up converting unrelated markdown, so I need to find a way to only convert highlighted text or something like that.

1 Like

Yes, as soon as someone inputs something like:
< something >[ something ] or
< something >{ something }
that isn’t intended for furigana, it breaks. I don’t know if it would be possible to inject a custom rule into markdown-it through a userscript. I haven’t even attempted it – the “ugly hack”-solution that I implemented was already hard enough for me and well beyond my knowledge of javascript project structure ^^
I also had to inject into the save() function – probably because Discord Discourse doesn’t accept a cooked string if it doesn’t match the raw input? Therefore I convert the furigana markup in the raw input right before save() is called.

1 Like

Version 1.2 patch-notes:

Ruby to furigana markup feature

As soon as ruby markup is detected in the input box, IME2Furigana now offers to convert it into the more compact furigana markup form.

If I broke something please let me know.
Link to previous script version for downgrading in case version 1.2 doesn’t work

2 Likes