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

Content deleted Content added
forgot a check
comment
 
(8 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 = {
title: "P1476",
nativeLabel: "P1705",
officialName: "P1448"};,
nameInNativeLanguage: "P1559"
};
var nameInKana = "P1814";
var pnum;
// Try getting nameInKana as a qualifier to some properties
for (var prop in properties) {
var pnum = properties[prop];
if (response.claims[pnum]) {
&& var kanji = response.claims[pnum][0].mainsnak.datavalue.value.text == wikidataKanji;
if (kanji.replace(/ /g, "") == wikidataKanji.replace(/ /g, "")
&& response.claims[pnum][0].qualifiers
&& response.claims[pnum][0].qualifiers[nameInKana]) {
&& response.claims[pnum][0].qualifiers[nameInKana]) {
kana = response.claims[pnum][0].qualifiers[nameInKana][0].datavalue.value;
break;
}
}
}
Line 265 ⟶ 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 410 ⟶ 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) {