Diferencia entre revisiones de «MediaWiki:Gadget-Arcanum-autofill-page.js»

De La Coppermind
Ir a la navegación Ir a la búsqueda
m (tweak)
m (try)
Línea 20: Línea 20:
.then(function(json) {
.then(function(json) {
if (!json || !json.event) { return; }
if (!json || !json.event) { return; }
// the <arcanum-entry-info /> tag
// the arcanum-entry-info tag
const tag = '<arcanum-entry-info date="'+ (json.date || json.event_date) +'" event="'+ json.event +'">'+ json.event_name +'</arcanum-entry-info>';
const tag = '<'+'arcanum-entry-info date="'+ (json.date || json.event_date) +'" event="'+ json.event +'">'+ json.event_name +'<'+'/arcanum-entry-info>';
// the rest of the page
// the rest of the page
const page = tag +"<noinclude>\n\n== Users ==\n{{Special:WhatLinksHere/{{FULLPAGENAME}}|}}\n[[category: generated citations]]\n";
const page = tag +"<noinclude>\n\n== Users ==\n\{\{Special:WhatLinksHere/\{\{FULLPAGENAME}}|}}\n[[category: generated citations]]\n";
// only fill in the edit box if it is currently blank
// only fill in the edit box if it is currently blank
if (edit_box.value == '') {
if (edit_box.value == '') {

Revisión del 16:33 27 jul 2019

// 2018-08-22 auto-generate Cite:Arcanum pages for wob ref template

mw.hook('wikipage.editform').add(function () {

 // determine if this page is editing a Cite: Arcanum page
 const edit_box = document.querySelector('#editform textarea');
 // check that there is an edit box
 if (!edit_box || mw.config.get('wgCanonicalNamespace') !== 'Cite') return -1;
 // check that it's a page creation
 if (mw.config.get('wgArticleId') != 0) return -2;
 // check that it's an Arcanum page
 const page_name = mw.config.get('wgPageName');
 if (!page_name.startsWith('Cite:Arcanum-')) return -3;
 console.warn('gadget:', 'Arcanum-autofill-page')
 // 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) {
 if (!json || !json.event) { return; }
 // the arcanum-entry-info tag
 const tag = '<'+'arcanum-entry-info date="'+ (json.date || json.event_date) +'" event="'+ json.event +'">'+ json.event_name +'<'+'/arcanum-entry-info>';
 // the rest of the page
 const page = tag +"\n\n== Users ==\n\{\{Special:WhatLinksHere/\{\{FULLPAGENAME}}|}}\n\n";
 // only fill in the edit box if it is currently blank
 if (edit_box.value == ) {
   edit_box.value = page;
   console.warn('gadget:', 'Arcanum-autofill-page', 'filled')
   // preview the page
   document.querySelector('[name="wpPreview"]').click()
 }
   })

})