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

m
for now
m (only move notices on proper viewings, not on diffs or other weird queries)
m (for now)
}
 
})
 
/* 2018-09-16 display Arcanum entry on Cite:Arcanum-X page */
$(function () {
// check that there is an edit box
if (!mw.config.get('wgCanonicalNamespace') !== 'Cite') return -1;
// check that it's an Arcanum page
const page_name = mw.config.get('wgPageName');
if (!page_name.startsWith('Cite:Arcanum-')) return -3;
// work out the api url
const entry = page_name.split('-')[1];
const url = 'https://wob.coppermind.net/api/entry/'+ entry +'/';
// start fetching from Arcanum
fetch(url)
.then(function(resp) { return resp.json() })
.then(function(json) {
// debugging:
console.log('Entry '+ entry, json);
// create containing element
const entry = document.createElement('article');
entry.classList.add('arcanum-entry');
// add lines
json.lines.forEach(line => {
// create speaker element
const speaker = document.createElement('h4')
speaker.innerText = line.speaker
// append the speaker and html from the line
entry.appendChild(entry)
entry.innerText += line.text
})
// place container on page
console.log(entry)
})
})