Diferencia entre revisiones de «MediaWiki:Gadget-Arcanum-fetch-quote.js»

De La Coppermind
Ir a la navegación Ir a la búsqueda
m (name functions)
(Allow links to 17S posts in the fetched quote (noticed while patrolling Cite:Arcanum-1219))
 
Línea 23: Línea 23:
 
const speaker = document.createElement('h4');
 
const speaker = document.createElement('h4');
 
speaker.innerText = line.speaker;
 
speaker.innerText = line.speaker;
if (speaker.innerText.includes('href') && speaker.innerText.includes('twitter.com')) {
+
if (speaker.innerText.includes('href') && (speaker.innerText.includes('twitter.com') || speaker.innerText.includes('17thshard.com'))) {
 
// speaker is a link to twitter, so show it as such
 
// speaker is a link to twitter, so show it as such
 
speaker.innerHTML = speaker.innerText
 
speaker.innerHTML = speaker.innerText

Revisión actual del 01:45 5 dic 2021

/* 2018-09-16 display Arcanum entry on Cite:Arcanum-X page */
function show_arcanum_entry() {
  // 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.warn('gadget:', 'Arcanum-fetch-quote')
  console.debug('Arcanum:', 'fetch', url);
  fetch(url)
    .then(function fetch_to_json(resp) { return resp.json() })
    .then(function show_Arcanum_on_page(json) {
  // debugging:
  console.debug('Arcanum:', 'entry '+ entry, json);
  // create containing element
  const entry_el = document.createElement('article');
  entry_el.classList.add('arcanum-entry');
  // add lines
  json.lines.forEach(function show_each_line(line) {
    // create speaker element
    const speaker = document.createElement('h4');
    speaker.innerText = line.speaker;
    if (speaker.innerText.includes('href') && (speaker.innerText.includes('twitter.com') || speaker.innerText.includes('17thshard.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);
    });
};
mw.hook('wikipage.content').add(show_arcanum_entry)