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

Content deleted Content added
add wikidata reading source
comment
 
(13 intermediate revisions by the same user not shown)
Line 51:
https://en.wikipedia.org/wiki/Ninjō - No interlanguage, but wiktionary
https://en.wikipedia.org/wiki/Seiza - Interlanguage failed, but wiktionary
https://en.wikipedia.org/wiki/Epsomite - No interlanguage, but wiktionary "see" Table
https://en.wikipedia.org/wiki/Bakayaro!_I%27m_Plenty_Mad - only part of parenthesis extracted
 
Line 213 ⟶ 214:
function parseKanaClaim(response) {
var kana;
var properties = {
if (response.claims.P1476 && response.claims.P1476 == wikidataKanji
&& response.claims. title: "P1476[0].qualifiers",
nativeLabel: "P1705",
&& response.claims.P1476[0].qualifiers.P1814) {
// title w/ name in kana officialName: "P1448",
nameInNativeLanguage: "P1559"
kana = response.claims.P1476[0].qualifiers.P1814[0].datavalue.value;
};
} else if (response.claims.P1705 && response.claims.P1705 == wikidataKanji
var nameInKana = "P1814";
&& response.claims.P1705[0].qualifiers
&& response.claims.P1705[0].qualifiers.P1814) {
// Try getting nameInKana as a qualifier to some properties
// native label w/ name in kana
for (var prop in properties) {
kana = response.claims.P1705[0].qualifiers.P1814[0].datavalue.value;
var pnum = properties[prop];
} else if (response.claims.P1448 && response.claims.P1448 == wikidataKanji
&& response.claims.P1448[0].qualifiers
if && (response.claims.P1448[0pnum].qualifiers.P1814) {
var kanji &&= response.claims.P1705[pnum][0].qualifiersmainsnak.datavalue.value.text;
// official name w/ name in kana
if (kanji.replace(/ /g, "") == wikidataKanji.replace(/ /g, "")
kana = response.claims.P1705[0].qualifiers.P1814[0].datavalue.value;
} else if ( && response.claims[pnum][0].P1814) {qualifiers
&& response.claims.P1476[pnum][0].qualifiers.P1814[nameInKana]) {
// name in kana
kana = response.claims.P1814[pnum][0].mainsnakqualifiers[nameInKana][0].datavalue.value;
} else { break;
// name in kana }
}
}
 
// Try getting nameInKana as a general claim
if (!kana && response.claims.P1448[0nameInKana].qualifiers) {
prop = "nameInKana";
kana = response.claims.P1476[0nameInKana].qualifiers.P1814[0].mainsnak.datavalue.value;
}
// We couldn't find nameInKana
if (!kana) {
getInterlanguage();
return;
Line 239 ⟶ 252:
displayKana(kana);
$("#kanjiInfo").addClass("kanjiInfo-wikidata");
$("#kanjiInfo").addClass("kanjiInfo-wikidata-" + prop);
}
 
Line 255 ⟶ 269:
success: function(response) {
var pageId = mw.config.get( 'wgArticleId' );
var langlinkspage = response.query.pages[pageId].langlinks;
var langlinks = page ? page.langlinks : undefined;
var jaLabel;
if (langlinks) {
Line 400 ⟶ 415:
// Wiktionary adds readings as furigana
var headword = parsed.find(".headword:lang(ja)").first();
var seeTable = parsed.find(".Jpan ruby").first();
var kanji = "";
var kana = "";
if (headword.length) {
// Wiktionary already binds their kana, so we have to undo the process to get
// the constituent parts, at least with the current markup
var childNodes = headword[0].childNodes;
for (let i = 0;var ichildNodes <= headword[0].childNodes.length; i++) {
for (let i = 0; i < childNodes.length; i++) {
if (childNodes[i].nodeName == "RUBY") {
var ruby = $ if (childNodes[i]).nodeName //== convert back to JQuery for"RUBY") convenience{
var ruby = $(childNodes[i]); // convert back to JQuery for convenience
ruby.children("rp").remove();
kana += ruby.children("rtrp").detach().textremove();
kanjikana += ruby.children("rt").detach().text();
kanji += ruby.text();
} else if (childNodes[i].nodeType == 3) { // "#text"
kanji += childNodes[i].nodeValue;
kana += childNodes[i].nodeValue;
}
}
if (kanji != wikidataKanji) { return; }
} else if (seeTable.length) {
kanji = seeTable.children("rb").text();
rubykana = seeTable.children("rprt").removetext();
} else {
return;
}
if (kanji != wikidataKanji) { return; }
 
if (kana) {