Diferencia entre revisiones de «MediaWiki:Common.js»

1353 bytes añadidos ,  hace 5 años
m
move code to everyone, add fix for twitter things
m (protect against bad loads)
m (move code to everyone, add fix for twitter things)
})
})
 
/* 2018-09-16 display Arcanum entry on Cite:Arcanum-X page */
$(function () {
// check that it's an Arcanum page
const page_name = mw.config.get('wgPageName');
if (!page_name.startsWith('Cite:Arcanum-')) return;
// work out the api url
const entry = page_name.split('-')[1];
const url = 'https://wob.coppermind.net/api/entry/'+ entry +'/';
// start fetching from Arcanum
console.log('fetching '+ url);
fetch(url)
.then(function(resp) { return resp.json() })
.then(function(json) {
// debugging:
console.log('Entry '+ entry, json);
// create containing element
const entry_el = document.createElement('article');
entry_el.classList.add('arcanum-entry');
// add lines
json.lines.forEach(function(line) {
// create speaker element
const speaker = document.createElement('h4');
speaker.innerText = line.speaker;
if (speaker.innerText.includes('href') && speaker.innerText.includes('twitter.com')) {
// speaker is a link to twitter, so show it as such
speaker.innerHTML = speaker.innerText
}
// append the speaker and html from the line
entry_el.appendChild(speaker);
entry_el.innerHTML += line.text;
});
// place container on page
const users_el = document.getElementById('Users').parentElement
users_el.parentElement.insertBefore(entry_el, users_el);
});
});
40 275

ediciones