User:Opencooper/showKanji-dev.js: Difference between revisions

Content deleted Content added
tweak
update Wiktionary parsing
Line 4:
 
// TODO: Reject if any base/reading has too low/high of a ratio.
// TODO: <rb> is not actually in the whatcg standard...
 
// License: CC0
Line 378 ⟶ 379:
var html = response.parse.text["*"];
var parsed = $($.parseHTML(html));
 
// Equivalent: $(".headword:lang(ja)").siblings(".Jpan.form-of:lang(ja)").first().text()
// Wiktionary tags itsadds readings with the "form-of"as classfurigana
var headword = parsed.find(".headword:lang(ja) ruby").first();
headword.children("rp").remove();
var kana = headword.siblingschildren(".Jpan.form-of:lang(ja)rt").firstdetach().text();
if (headword.text() != wikidataKanji) { return; }
// Wiktionary tags its readings with the "form-of" class
var kana = headword.siblings(".Jpan.form-of:lang(ja)").first().text();
if (kana) {
kana = kana.toHalfWidth();
if (!kanjiRegexes.kanaOnly.test(kana)) { return; }
 
if (kana) {
displayKana(kana);
$("#kanjiInfo").addClass("kanjiInfo-wiktionary");
 
// Extra stuff just for fun
var definition = headword.parent().parent().siblings("ol").children("li").first().text();
$("#kanjiInfo").prop("title", definition);
}