User:Bluemoose/monobook.js/catkey.js

From Wikipedia, the free encyclopedia

Note: After saving, you have to bypass your browser's cache to see the changes. Firefox/Mozilla/Safari: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Internet Explorer: press Ctrl-F5, Opera/Konqueror: press F5.

//<pre><nowiki>

addOnloadHook( function() { if(!document.forms.editform) { return; }
name = document.getElementsByTagName("h1")[0].innerHTML.replace("Editing ", "").replace(/ \(.*?\)/, "");

intLast = name.lastIndexOf(" ");
lname = name.substr(intLast + 1);

fname = name.substr(0, intLast);
name = lname + (fname ? ", " + fname : "");

txt = document.editform.wpTextbox1.value;
introTxt = txt.match(/\(([^\)]*?[0-9]{4}[^\)]*?)\)/);
if (introTxt) { years = introTxt[1].match(/[0-9]{4}/g); } else { years = []; }

newTxt = "[[Category:|" + name + "]]" + (years[0] ? "\n[[Category:" + years[0] + " births|" + name + "]]" : "") + (years[1] ? "\n[[Category:" + years[1] + " deaths|" + name + "]]" : "");

mwCustomEditButtons[mwCustomEditButtons.length] = {"imageFile": 'http://upload.wikimedia.org/wikipedia/en/b/b1/Button_key.PNG', "speedTip": 'Insert category key', "tagOpen": '', "tagClose": newTxt, "sampleText": ''}; } );

//</nowiki></pre>