User:KillerChihuahua/monobook.js/dates.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:KillerChihuahua/monobook.js/dates. |
function formatdates() {
var txt = document.editform.wpTextbox1;
// century
txt.value = txt.value.replace(/\[\[(\d{1,2}(?:st|nd|rd|th)) (century)\]\]/gi, '$1 century');
txt.value = txt.value.replace(/\[\[\d{1,2}(?:st|nd|rd|th) century\|(\d{1,2}(?:st|nd|rd|th))\]\]/gi, '$1');
txt.value = txt.value.replace(/\[\[\d{1,2}(?:st|nd|rd|th) century\|(\d{1,2}(?:st|nd|rd|th)) (centuries)\]\]/gi, '$1 centuries');
// decades
txt.value = txt.value.replace(/\[\[(\d{1,4}s)\]\]/gi, '$1');
// months
txt.value = txt.value.replace(/\[\[(January|February|March|April|May|June|July|August|September|October|November|December)\]\]/gi, '$1');
txt.value = txt.value.replace(/\[\[January\|(Jan)\]\]/gi, '$1');
txt.value = txt.value.replace(/\[\[February\|(Feb)\]\]/gi, '$1');
txt.value = txt.value.replace(/\[\[March\|(Mar)\]\]/gi, '$1');
txt.value = txt.value.replace(/\[\[April\|(Apr)\]\]/gi, '$1');
txt.value = txt.value.replace(/\[\[May\|(May)\]\]/gi, '$1');
txt.value = txt.value.replace(/\[\[June\|(Jun)\]\]/gi, '$1');
txt.value = txt.value.replace(/\[\[July\|(Jul)\]\]/gi, '$1');
txt.value = txt.value.replace(/\[\[August\|(Aug)\]\]/gi, '$1');
txt.value = txt.value.replace(/\[\[September\|(Sep)\]\]/gi, '$1');
txt.value = txt.value.replace(/\[\[October\|(Oct)\]\]/gi, '$1');
txt.value = txt.value.replace(/\[\[November\|(Nov)\]\]/gi, '$1');
txt.value = txt.value.replace(/\[\[December\|(Dec)\]\]/gi, '$1');
txt.value = txt.value.replace(/\[\[((?:January|February|March|April|May|June|July|August|September|October|November|December) \d{3,4})\]\]/gi, '$1');
// days of the week
txt.value = txt.value.replace(/\[\[(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday)\]\]/gi, '$1');
txt.value = txt.value.replace(/\[\[(Mondays|Tuesdays|Wednesdays|Thursdays|Fridays|Saturdays|Sundays)\]\]/gi, '$1');
txt.value = txt.value.replace(/\[\[(Mon|Tue|Tues|Wed|Thu|Thur|Thurs|Fri|Sat|Sun)\]\]/gi, '$1');
txt.value = txt.value.replace(/\[\[Monday\|(Mondays)\]\]/gi, '$1');
txt.value = txt.value.replace(/\[\[Tuesday\|(Tuesdays)\]\]/gi, '$1');
txt.value = txt.value.replace(/\[\[Wednesday\|(Wednesdays)\]\]/gi, '$1');
txt.value = txt.value.replace(/\[\[Thursday\|(Thursdays)\]\]/gi, '$1');
txt.value = txt.value.replace(/\[\[Friday\|(Fridays)\]\]/gi, '$1');
txt.value = txt.value.replace(/\[\[Saturday\|(Saturdays)\]\]/gi, '$1');
txt.value = txt.value.replace(/\[\[Sunday\|(Sundays)\]\]/gi, '$1');
// ranked days
txt.value = txt.value.replace(/\[\[(\d{1,2}(?:st|nd|rd|th))\]\]/gi, '$1');
// misconfigured
txt.value = txt.value.replace(/\[\[((?:January|February|March|April|May|June|July|August|September|October|November|December) \d{1,2}(?:st|nd|rd|th))\]\]/gi, '$1');
txt.value = txt.value.replace(/\[\[(?:January|February|March|April|May|June|July|August|September|October|November|December) \d{1,2}\|(\d{1,2})\]\]/gi, '$1');
// year
txt.value = txt.value.replace(/(\*)\[\[(\d{1,4})\]\]/gi, '$1$2');
txt.value = txt.value.replace(/(\()\[\[(\d{1,4})\]\]/gi, '$1$2');
txt.value = txt.value.replace(/(\|)\[\[(\d{1,4})\]\]/gi, '$1$2');
txt.value = txt.value.replace(/\[\[(\d{1,4} (?:AD|BC|CE|BCE))\]\]/gi, '$1');
txt.value = txt.value.replace(/\[\[\d{1,4} (?:AD|BC|CE|BCE)\|(\d{1,4})\]\]/gi, '$1');
txt.value = txt.value.replace(/([^\]][^\]]{2})\[\[(\d{1,4})\]\]/gi, '$1$2');
txt.value = txt.value.replace(/([^\]][^\]]{2})\[\[(\d{1,4})\]\]/gi, '$1$2');
txt.value = txt.value.replace(/([^\]][^\]]{2})\[\[(\d{1,4})\]\]/gi, '$1$2');
txt.value = txt.value.replace(/\[\[\d{1,4}\|(\d{1,2})\]\]/gi, '$1');
txt.value = txt.value.replace(/\[\[\d{1,4}\|(\d{1,2})\]\]/gi, '$1');
txt.value = txt.value.replace(/\[\[\d{1,4}\|(\d{1,2})\]\]/gi, '$1');
// Add a tag to the summary box
var txt = document.editform.wpSummary;
var summary = "links as per MoS";
if (txt.value.indexOf(summary) == -1) {
if (txt.value.match(/[^\*\/\s][^\/\s]?\s*$/)) {
txt.value += " | ";
}
txt.value += summary;
}
// Press the diff button to check it
document.editform.wpDiff.click()
}
addOnloadHook(function () {
if(document.forms.editform) {
addLink('p-cactions', 'javascript:formatdates()', '1Jan2001', 'ca-datefixer', 'Fixes some date formatting', '', '');
}
});