musician.appendChild(wdd);
}
+ // Get the description from Wikipedia
if (r.hasOwnProperty('wplink')) {
+ wpapi = 'https://en.wikipedia.org/w/api.php?origin=*&format=json&action=query&prop=extracts&explaintext=true&exintro=true&titles=';
var wplink = r.wplink.value;
// Strip the WP title from the link
- // https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&explaintext=true&exintro=true&titles=CANO
- var description = ''; // extract text from wplink
- var wdd = document.createElement('div');
- var wddl = document.createElement('label');
- wddl.innerText = description;
- wdd.appendChild(wddl);
- musician.appendChild(wdd);
- }
+ wptitle = wplink.substring(wplink.lastIndexOf('/') + 1);
+ var req = new window.XMLHttpRequest();
+ req.open('GET', wpapi + wptitle);
+ req.onload = function (evt) {
+ var r = JSON.parse(req.response);
+ var k = Object.getOwnPropertyNames(r.query.pages)[0];
+ var description = r.query.pages[k].extract;
+
+ // Just the first line will do
+ var linefeed = description.indexOf('\n');
+ var period = description.indexOf('. ');
+ if (linefeed > 0) {
+ description = description.substring(0, linefeed);
+ } else if (period > 0) {
+ description = description.substring(0, period + 1);
+ }
+ var wdd = document.createElement('p');
+ var wpa = document.createElement('a');
+ wpa.href = wplink;
+ wpa.innerText = '(Wikipedia)';
+ wdd.innerText = description + ' ';
+ wdd.appendChild(wpa);
+ musician.appendChild(wdd);
+ }
+ req.send();
+ }
function addWDValue(property, propertyLabel, label, isLink, linkFormatter) {
var value = '';