User:PhiLiP/taxobox.js
外观
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
/* <nowiki>
*
* taxobox.js by [[User:FelixReimann]] with help from [[User:Ricordisamoa]]
* based on [[wikidata:User:Ricordisamoa/Wikispecies.js]]
* based on [[wikidata:User:FelixReimann/taxobox.js]]
*/
$(document).ready(function(){
// only on entities, not properties or other namespaces
if ( mw.config.get('wgNamespaceNumber') !== 0 ) return ;
if ( mw.config.get('wgAction') !== 'view' ) return ;
var infobox = document.querySelector('.infobox.biota');
if( infobox === null ) return;
var language = 'zh'; // mw.user.options.get('variant');
var wbId = mw.config.get('wgWikibaseItemId');
var count = 5;
if (mw.config.get('taxoboxCount')) {
count = mw.config.get('taxoboxCount');
}
var template = '<div style="width: 240px; margin-left: 5px; float: right;">{{Taxobox|qid=' + wbId + '|count=' + count + '|lang=' + language + '}}<div class="wikibase-taxobox-references" style="clear:right;"><references/></div></div>';
// https:cadat?action=parse&text={{Taxobox|qid=Q36146}}&prop=text&contentmodel=wikitext&format=jsonfm
$.ajax({
url: '//www.wikidata.org/w/api.php',
jsonp: 'callback',
dataType: 'jsonp',
data: {
action:'parse',
format:'json',
text: template,
contentmodel:'wikitext',
prop:'text'
},
success: function(data){
var text=data.parse.text;
$(infobox).replaceWith(text['*']); // TODO insert text
}
});
});
//</nowiki>