Difference between revisions of "User:Fbstj/gadget/history-test.js"

m
m (put it outside the wrapping H2)
 
})
 
/* 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;
// 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);
});
});