User:Opencooper/showKanji

Source: Wikipedia, the free encyclopedia.
An example of how the Japanese text would display under the page title. Notice the furigana.

showKanji.js shows the corresponding Japanese kanji of an article on the English Wikipedia—as well as any kana—under the page title. See below for installation instructions, how to style it, details on how it works, and how to hide the furigana or omit katakana-only results.

Installation

To install the script, add the following to your common.js page:

importScript('User:Opencooper/showKanji.js'); // Backlink: [[User:Opencooper/showKanji.js]]

Styling

By default, the script does not apply any styling to the kanji, allowing you to format it to your taste in your common.css page. The following is how I style it for myself:

#kanjiInfo {
	font-size: 65%;
	font-family: "Hiragino Mincho ProN W3", serif; /* The font specified here has to be already installed */
	color: teal;
	padding-left: 0.2em;
	padding-top: 0.1em;
}

To style the results differently on mobile, edit your minerva.css page (to make it not run on mobile, import this script in your vector.js only).

Omitting

You can hide the furigana by adding the following to your common.css page:

#kanjiInfo rt {
	display: none;
}

If you don't want to show results that only consist of katakana, add the following to your common.css page (though note you'll miss out on terms written in katakana for stylistic purposes, such as organism names):

.kanjiInfo-katakana-only {
	display: none;
}

For hiragana-only results, use .kanjiInfo-hiragana-only instead.

If you want to show Latin-only results (which will be the title 99% of the time, but they might also have furigana):

.kanjiInfo-latin-only {
	display: block !important;
}

How it works

For kanji, the script gets the Japanese label of the page in Wikidata. If the kanji is in Latin characters only, it is not shown. For kana, first it tries to get the name in kana Wikidata property. If that isn't found, it tries to obtain it from the text of the Japanese article (usually successful). Lastly, it tries to get it from the English Wiktionary. Not every article will have kanji or kana that can be obtained.

If it obtains kana, it tries to clean up kana that is redundant to the kanji by running a separate script. This script looks for matching sequential hiragana, katakana, or Latin when searching from right to left (except for spaces, which are LTR). It works for most cases, but could choke if it doesn't know how to separate a title, in which case the full furigana is shown.

FAQ

I don't see kanji for a term that should have it
Assuming it's not a bug, you can always contribute the kanji yourself. The best way is to add a Japanese label on Wikidata. I would suggest enabling the labelLister gadget to help you do this.
I don't see any furigana, even though the Japanese article has the kana
The script assumes that the first sentence of the Japanese article will follow the format of ${kanji title} (kana) and tries to be conservative. If the kana is anywhere else or the parenthesis has other formatting in it, the script might fail (depending on the type of assumption it would require, this could be fixable for certain cases).
I see kanji, but no furigana for a page without a corresponding Japanese article
That means that the Japanese label was found on Wikidata, but Wikidata didn't have a name in kana property (I'm not sure how good the coverage of this property is, but it's probably not that widespread yet). You'll have to add it yourself (making sure that the addition is appropriate).
Only part of the furigana is shown
When the script scrapes the kana from the Japanese article, it makes assumptions so it doesn't capture too much. Please report the specific page it is failing on and I'll try to fix it.
The kanji/furigana is wrong/non-standard
This script only programmatically gets what it can find. In reality, a term can have multiple kanji, different readings, etc. If there are any erroneous results, they should be fixed on Wikidata, the corresponding Japanese page, or the English Wiktionary page. If those are correct, then the fault is with the script and you should report a bug, noting the specific page.
Can we have this for x language/script?
All my contributions are released into public domain, so you are free to fork this script and make your own variation. It's pretty simple getting labels from Wikidata or the interlanguage links. The only thing special that this userscript does is getting kana readings.
I don't like the cleaned up furigana
The original full furigana is still there, but hidden in a class called unbound. Just hide bound and show unbound in your CSS.

Feedback

When reporting bugs, please include the specific article it is failing on. If the script doesn't work on any pages at all, the method of displaying the kanji might be interfering with another userscript. Only the Vector and Minerva skins have been tested.

License

This script and any associated files are licensed under

Creative Commons Zero
.