MediaWiki:Gadget-Arcanum-fetch-quote.js
Ir a la navegación
Ir a la búsqueda
Nota: tras guardar, quizás necesites actualizar la caché de tu navegador para ver los cambios.
- Firefox/Safari: Mantén presionada la tecla Mayús mientras pulsas el botón Actualizar, o presiona Ctrl+F5 o Ctrl+R (⌘+R en Mac)
- Google Chrome: presiona Ctrl+Shift+R (⌘+Mayús+R en Mac)
- Internet Explorer: mantén presionada Ctrl mientras pulsas Actualizar, o presiona Ctrl+F5
- Opera: dirígete a Menú → Configuración (Opera → Preferencias en Mac) y luego a Privacidad y seguridad → Borrar datos de navegación → Imágenes y archivos en caché.
/* 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)