Diferencia entre revisiones de «MediaWiki:Common.js»

m
try this
m (auto-preview)
m (try this)
});
 
/* 2018-0608-26 first demo of22 auto-generatedgenerate Cite:Arcanum pages for {{wob ref}} */
// determine if this page is a Cite: Arcanum page
function check_for_arcanum() {
 
const edit_box = document.querySelector('.editButtons');
// 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;
 
const entry = page_name.split('-')[1];
return 'https://wob.coppermind.net/api/entry/'+ entry +'/';
};
function build_from_json(json) {
console.log(json);
const tag = '<arcanum-entry-info date="'+ (json.date || json.event_date) +'" event="'+ json.event +'">'+ json.event_name +'</arcanum-entry-info>';
const page = tag +"<noinclude>\n\n== Users ==\n{{Special:WhatLinksHere/{{FULLPAGENAME}}|}}\n";
document.querySelector('#editform textarea').value = page;
document.querySelector('[name="wpPreview"]').click()
};
/* auto-fill [[Cite: Arcanum-@entry]] pages*/
$(function () {
// determine if this page is editing a Cite: Arcanum page
const url = check_for_arcanum()
const edit_box = document.querySelector('.editButtons#editform textarea');
if (url < 0) return
// check that there is an edit box
fetch(url).then(function(resp) { return resp.json() }).then(build_from_json)
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;
// work out the api url
const entry = page_name.split('-')[1];
return const url = 'https://wob.coppermind.net/api/entry/'+ entry +'/';
// start fetching from Arcanum
fetch(url)
fetch(url) .then(function(resp) { return resp.json() }).then(build_from_json)
.then(function(json) {
// 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 +"<noinclude>\n\n== Users ==\n{{Special:WhatLinksHere/{{FULLPAGENAME}}|}}\n";
// only fill in the edit box if it is currently blank
if (edit_box.value == '') {
edit_box.value = page;
// preview the page
document.querySelector('#editform textarea[name="wpPreview"]').value = page;click()
}
})
})
40 275

ediciones