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

Content deleted Content added
temp
rework to handle bound headwords
Line 381:
 
// Wiktionary adds readings as furigana
var headword = parsed.find(".headword:lang(ja) ruby").first();
headword.children("rp").remove();
var kanakanji = headword.children("rt").detach().text();
var kana = "";
if (headword.text() != wikidataKanji) { return; }
// Wiktionary already binds their kana, so we have to undo the process to get
// the constituent parts, at least with the current markup
for (child in headword[0].childNodes) {
if (child.nodeName == "RUBY") {
var ruby = $(child) // convert back to JQuery for convenience
headword ruby.children("rp").remove();
var kana = ruby.children("rt").detach().text();
var kanji = ruby.text();
} else if (child.nodeType == 3) { // "#text"
kanji += child.nodeValue;
kana += child.nodeValue;
}
}
if (headword.text()kanji != wikidataKanji) { return; }
 
if (kana) {
Line 391 ⟶ 406:
 
// Extra stuff just for fun
var definition = headword.parent().parent().siblings("ol").children("li").first().text();
$("#kanjiInfo").prop("title", definition);
}