User:Stevenliuyi/Wikidata.js

$(function ($) { var translate = {    'en': {      notfound: "Wikidata item not found.",      intro: "Wikidata: ",      nolabel: "(No label)",      nodescription: "no description given",      aliases: "Aliases: ",      noaliases: "None"    },    'zh': {      notfound: "维基数据中未找到该项目，点击创建新项",      intro: "维基数据",      nolabel: "[无标签]",      nodescription: "无描述",      aliases: "别名",      noaliases: "无"    }  }  var namespace = mw.config.get('wgCanonicalNamespace');  if (namespace === '') {    var page = mw.config.get('wgTitle');  } else {    var page = namespace + ':' + mw.config.get('wgTitle');  }  $.ajax({ url: '//www.wikidata.org/w/api.php', data: { 'format': 'json', 'action': 'wbgetitems', 'sites': mw.config.get('wgDBname'), 'titles': page, 'props': 'info|labels|descriptions|aliases', 'languages': mw.config.get('wgPageContentLanguage') },   dataType: 'jsonp', success: function (data) { /*     var d = $(" "); $("#contentSub").append(d); if (data.success) { for (var i in data.items) { var lang = mw.config.get('wgPageContentLanguage'), m = translate[ lang ] || translate.en; if (i == -1) { d.append($("").attr("href", "//www.wikidata.org/wiki/Special:CreateItem").text( m.notfound )) } else { var item = data.items[i], i = 0, aliases = []; try { for (i < item.aliases[lang].length; i++) { aliases.push(item.aliases[lang][i].value); }           } catch (e) { } d.append($("").attr("href", "//www.wikidata.org/wiki/" + item.title).text(m.intro + ( item.labels ? item.labels[lang].value : m.nolabel ) + " (" + item.title + ")")).append($(" ").text(", ")).append($("").text(item.descriptions ? item.descriptions[lang].value : m.nodescription)).append($(" ")).append($(" ").text(m.aliases + (aliases.join(", ") || m.noaliases))) }       }      }      var d = $(""); $("#p-views ul").append(d); if (data.success) { for (var i in data.items) { var lang = mw.config.get('wgPageContentLanguage'), m = translate[ lang ] || translate.en; if (i == -1) { d.append($(" ").append($("").attr("href", "//www.wikidata.org/wiki/Special:CreateItem").attr("title", m.notfound).append($(" ").attr("src", "//upload.wikimedia.org/wikipedia/commons/thumb/f/ff/Wikidata-logo.svg/30px-Wikidata-logo.svg.png")))); } else { var item = data.items[i], i = 0, aliases = []; try { for (i < item.aliases[lang].length; i++) { aliases.push(item.aliases[lang][i].value); }           } catch (e) { } d.append($(" ").append($("").attr("href", "//www.wikidata.org/wiki/Special:CreateItem").attr("title", ( item.labels ? item.labels[lang].value : m.nolabel ) + " (" + item.title + ")：" + ( item.descriptions ? item.descriptions[lang].value : m.nodescription )).append($(" ").attr("src", "//upload.wikimedia.org/wikipedia/commons/thumb/f/ff/Wikidata-logo.svg/30px-Wikidata-logo.svg.png")))); }       }      }

/* 

var d1 = $(" ").attr("class", "metadata topicon noprint nopopups"); $("#mw-content-text").prepend(d1); if (data.success) { for (var i in data.items) { var lang = mw.config.get('wgPageContentLanguage'), m = translate[ lang ] || translate.en; if (i == -1) { d1.append($("").attr("href", "//www.wikidata.org/wiki/Special:CreateItem").text($(" ").attr("src", "//upload.wikimedia.org/wikipedia/commons/thumb/f/ff/Wikidata-logo.svg/30px-Wikidata-logo.svg.png").attr("alt", m.notfound))); }

else { var item = data.items[i], i = 0, aliases = []; try { for (i < item.aliases[lang].length; i++) { aliases.push(item.aliases[lang][i].value); }           } catch (e) { } d.append($("").attr("href", "//www.wikidata.org/wiki/" + item.title).text(m.intro + ( item.labels ? item.labels[lang].value : m.nolabel ) + " (" + item.title + ")")).append($(" ").text(", ")).append($("").text(item.descriptions ? item.descriptions[lang].value : m.nodescription)).append($(" ")).append($(" ").text(m.aliases + (aliases.join(", ") || m.noaliases))) }       }      }

} }); });