User:RossPatterson/ISO8601 to mmm dd yyyy.js
Appearance
(Redirected from User:RossPatterson/monobook.js/ISO8601 to mmm dd yyyy.js)
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:RossPatterson/ISO8601 to mmm dd yyyy. |
/* Add a tab called "de-iso8601" to convert yyyy-mm-dd dates to mmm dd, yyyy */
/* NOTE: This script is agressive. It doesn't try to avoid any changes - if it finds
a string in "nnnn-nn-nn" format, it will attempt to convert it. You are
well-advised to examine the diffs closely, and to especially look for
partially-successful conversions (i.e., "_FiXmE_..._fIxMe") and dates buried
in URLs (e.g., ".../2007-11-05_article.html" -> ".../November 5, 2007_article.html"
and correct them by hand!
Inspired by [[User:MJCdetroitMJCdetroit's]] Units of measure formatting and conversion tool and date formatting tool ([[User:MJCdetroit/monobook.js]])
Simply add ''importScript("User:RossPatterson/ISO8601_to_mmm_dd_yyyy.js");'' to your own monobook.js and clear the cache before it will work.
*/
function ISO8601_to_mmm_dd_yyyy() {
var txt = document.editform.wpTextbox1;
// Find and mark yyyy-mm-dd dates to be changed:
txt.value = txt.value.replace(/(\d\d\d\d-\d\d-\d\d)/g, '_FiXmE_$1_fIxMe_');
// [[yyyy-mm-dd]] -> yyyy-mm-dd:
txt.value = txt.value.replace(/\[\[_FiXmE_(\d\d\d\d-\d\d-\d\d)_fIxMe_\]\]/g, '_FiXmE_$1_fIxMe_');
// yyyy-mm-dd -> mm dd, yyyy:
txt.value = txt.value.replace(/_FiXmE_(\d\d\d\d)-(\d\d)-(\d\d)_fIxMe_/g, '_FiXmE_$2 $3, $1_fIxMe_');
// 01, ... -> January, ... etc.:
txt.value = txt.value.replace(/_FiXmE_01 (\d\d, \d\d\d\d)_fIxMe_/g, '_FiXmE_January $1_fIxMe_');
txt.value = txt.value.replace(/_FiXmE_02 (\d\d, \d\d\d\d)_fIxMe_/g, '_FiXmE_February $1_fIxMe_');
txt.value = txt.value.replace(/_FiXmE_03 (\d\d, \d\d\d\d)_fIxMe_/g, '_FiXmE_March $1_fIxMe_');
txt.value = txt.value.replace(/_FiXmE_04 (\d\d, \d\d\d\d)_fIxMe_/g, '_FiXmE_April $1_fIxMe_');
txt.value = txt.value.replace(/_FiXmE_05 (\d\d, \d\d\d\d)_fIxMe_/g, '_FiXmE_May $1_fIxMe_');
txt.value = txt.value.replace(/_FiXmE_06 (\d\d, \d\d\d\d)_fIxMe_/g, '_FiXmE_June $1_fIxMe_');
txt.value = txt.value.replace(/_FiXmE_07 (\d\d, \d\d\d\d)_fIxMe_/g, '_FiXmE_July $1_fIxMe_');
txt.value = txt.value.replace(/_FiXmE_08 (\d\d, \d\d\d\d)_fIxMe_/g, '_FiXmE_August $1_fIxMe_');
txt.value = txt.value.replace(/_FiXmE_09 (\d\d, \d\d\d\d)_fIxMe_/g, '_FiXmE_September $1_fIxMe_');
txt.value = txt.value.replace(/_FiXmE_10 (\d\d, \d\d\d\d)_fIxMe_/g, '_FiXmE_October $1_fIxMe_');
txt.value = txt.value.replace(/_FiXmE_11 (\d\d, \d\d\d\d)_fIxMe_/g, '_FiXmE_November $1_fIxMe_');
txt.value = txt.value.replace(/_FiXmE_12 (\d\d, \d\d\d\d)_fIxMe_/g, '_FiXmE_December $1_fIxMe_');
// mmm 0d, yyyy -> mmm d, yyyy:
txt.value = txt.value.replace(/_FiXmE_(\w*) 0(\d, \d\d\d\d)_fIxMe_/g, '_FiXmE_$1 $2_fIxMe_');
// Unmark changed dates:
txt.value = txt.value.replace(/_FiXmE_(\w* \d{1,2}, \d\d\d\d)_fIxMe_/g, '$1');
}
function run_ISO8601_to_mmm_dd_yyyy() {
var txt = document.editform.wpTextbox1;
ISO8601_to_mmm_dd_yyyy();
// Add a tag to the summary box
var txt = document.editform.wpSummary;
var summary = "Change ISO8601-style dates to mmm dd, yyyy and unlink them";
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) {
mw.util.addPortletLink('p-cactions', 'javascript:run_ISO8601_to_mmm_dd_yyyy()', 'De-ISO8601', 'ca-de-iso8601', 'Change ISO8601-style dates to mmm dd, yyyy"', '', '');
}
});