Wikipedia:WikiProject Missing encyclopedic articles/NZ/Dictionary of New Zealand Biography/MCH.js
Appearance
<syntaxhighlight lang="javascript">
// ==UserScript==
// @name MCH stub creator
// @namespace http://opensourceexile.blogspot.com/
// @description Create wikipedia stubs from MCH bio pages
// @include http://www.teara.govt.nz/en/biographies/*
// ==/UserScript==
// See https://secure.wikimedia.org/wikipedia/en/wiki/Wikipedia:WikiProject_Missing_encyclopedic_articles/NZ/Dictionary_of_New_Zealand_Biography
var rawTitle=document.getElementsByName("DC.title")[0].content;
var rawName=rawTitle;
var first=rawTitle.substring(rawTitle.indexOf(', ')+2);
var last=rawTitle.substring(0,rawTitle.indexOf(', '));
var fixedName= rawTitle.substring(rawTitle.indexOf(', ')+2) + ' ' + rawTitle.substring(0,rawTitle.indexOf(', '));
var rawDates=document.getElementsByTagName("p").item(0).childNodes[0].textContent;
var birthDate=rawDates.substring(0,4);
var deathDate=rawDates.substring(5,9);
var rawBio=document.getElementsByTagName("p").item(1).childNodes[0].textContent;
if (rawBio.indexOf(' and ') == -1 ){
var regexpBio=/^(.*), ([^,]*)$/;
var cookedBio=rawBio.replace(regexpBio, "$1 and $2");
} else {
var cookedBio=rawBio;
}
var rawFooter=document.getElementById("footer-citation").childNodes[1].textContent;
var refAuthor=rawFooter.substring(rawFooter.indexOf(':')+1).substring(0,rawFooter.indexOf("'")-rawFooter.indexOf(':')-3);
var refLast=refAuthor.substring(refAuthor.lastIndexOf(' '));
var refFirst=refAuthor.substring(0,refAuthor.lastIndexOf(' '));
var rawDate=rawFooter.substring(rawFooter.indexOf('updated')+7)
var refDate=rawDate.substring(0,rawDate.indexOf('\n'));
var refURL=rawFooter.substring(rawFooter.indexOf('URL:')+5);
var regexpId=/^.*\/([^\/][^\/][^\/][^\/]?)\/.*$/;
var id=refURL.replace(regexpId,"$1");
alert("\n" + "'''" + fixedName + "''' (" + birthDate + "–" + deathDate + ")" + " was a [[New Zealand]] " + cookedBio.toLowerCase() + ".<ref name=\"DNZB " + last + "\">{{DNZB|title=" + fixedName + "|first=" + refFirst +"|last=" + refLast + "|id=" + id + "|accessdate=December 2011}}</ref>\n\n==References==\n{{Reflist}}\n\n{{Persondata <!-- Metadata: see [[Wikipedia:Persondata]]. --> \n| NAME = " + rawName + "\n| ALTERNATIVE NAMES = \n| SHORT DESCRIPTION = " + rawBio + "\n| DATE OF BIRTH = " + birthDate + "\n| PLACE OF BIRTH = \n| DATE OF DEATH = " + deathDate + "\n| PLACE OF DEATH = \n}}\n{{DEFAULTSORT:" + rawName +"}}\n\n[[Category:" + birthDate + " births]]\n[[Category:" + deathDate + " deaths]]\n[[Category:New Zealand people]]\n\n{{NewZealand-bio-stub}}\n\n")
</syntaxhighlight>