User:WOSlinker/milperson.js

function milperson_queryString(p) { var re = RegExp('[&?]' + p + '=([^&]*)'); var matches; if (matches = re.exec(document.location)) { try { return decodeURI(matches[1]); } catch (e) { } }   return null; } if(mw.config.get('wgNamespaceNumber') != -1 && mw.config.get('wgArticleId') != 0) { $( function milpersonEditButton {       mw.util.addPortletLink('p-cactions', mw.util.getUrl(null,{action:'edit',milperson:true}), 'milperson', 'p-milperson', 'MilPerson edit this page');   } )} String.prototype.trim = function { return this.replace(/^\s+|\s+$/g,""); }

if(mw.config.get('wgAction') == 'edit' && milperson_queryString('milperson') == 'true') { $(function rugbyEdit {

var sep = '\n';

var idx_start; var idx_end; var removed;

var myContent = document.getElementById('wpTextbox1').value; var idx1 = myContent.indexOf("=="); if (idx1 == -1) { idx1 = myContent.length; }

var myContentTop = myContent.substring(0,idx1); var myContentBottom = myContent.substring(idx1,99999999);

function findparam(param,removeit) {   re = new RegExp("\\|\\s*" + param + "\\s*="); var m = re.exec(myContentTop); try { idx_start = m.index; var idx_equals = myContentTop.indexOf("=", idx_start); idx_end = myContentTop.indexOf(sep, idx_start);

var result = myContentTop.substring(idx_equals+1,idx_end).trim;

if (removeit == "") { myContentTop = myContentTop.substring(0,idx_start)+myContentTop.substring(idx_end+1,99999999); } else { var removed = myContentTop.substring(idx_start,idx_equals+1)+sep; removed = removed.replace(param,removeit); myContentTop = myContentTop.substring(0,idx_start)+removed+myContentTop.substring(idx_end+1,99999999); }   return result; } catch (e) { return ""; } }

function insertparamvalue(param,paramvalue) {   re = new RegExp("\\|\\s*" + param + "\\s*="); var m = re.exec(myContentTop); try { idx_start = m.index; var idx_equals = myContentTop.indexOf("=", idx_start); idx_end = myContentTop.indexOf(sep, idx_start);

myContentTop = myContentTop.substring(0,idx_end)+paramvalue+myContentTop.substring(idx_end,99999999); } catch (e) { } }

var lived = findparam("lived","birth_date"); lived = lived.replace(/ \&ndash\; /,'\n|death_date= '); lived = lived.replace(/ \- /,'\n|death_date= '); lived = lived.replace(/ \– /,'\n|death_date= '); lived = lived.replace(/\&nbsp\;\- /,'\n|death_date= '); lived = lived.replace(/\&nbsp\;\– /,'\n|death_date= '); lived = lived.replace(/\&ndash\;/,'\n|death_date= '); lived = lived.replace(/\—/,'\n|death_date= ');

insertparamvalue("birth_date",lived);

myContentTop = myContentTop.replace(/\|placeofbirth/,'|birth_place '); myContentTop = myContentTop.replace(/\|placeofdeath/,'|death_place ');

myContent = myContentTop +myContentBottom;

if(document.getElementById('wpTextbox1').value != myContent) { document.getElementById('wpTextbox1').value=myContent; document.getElementById('wpSummary').value='update infobox, see '+'Template talk:Infobox person/birth death params'; document.getElementById('wpMinoredit').checked = true; };

} )}