Jump to content

User:CBM/dates.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
var monArray = new Array();
  monArray['January'] = 1;
  monArray['February'] = 2;
  monArray['March'] = 3;
  monArray['April'] = 4;
  monArray['May'] = 5;
  monArray['June'] = 6;
  monArray['July'] = 7;
  monArray['August'] = 8;
  monArray['September'] = 9;
  monArray['October'] = 10;
  monArray['November'] = 11;
  monArray['December'] = 12;
  monArray['Jan'] = 1;
  monArray['Feb'] = 2;
  monArray['Mar'] = 3;
  monArray['Apr'] = 4;
  monArray['May'] = 5;
  monArray['Jun'] = 6;
  monArray['Jul'] = 7;
  monArray['Aug'] = 8;
  monArray['Sep'] = 9;
  monArray['Sept'] = 9;
  monArray['Oct'] = 10;
  monArray['Nov'] = 11;
  monArray['Dec'] = 12;


$(function() {
//  alert(wgCanonicalNamespace);

  var disabled_urls = new Array('action=history');
  var unique_url = false;
  var wikiPreview = new Array('action=edit', 'action=submit');
  for (var i = 0; i < disabled_urls.length; i++) {
    if (document.location.href.indexOf(disabled_urls[i]) != -1)
      return;
  }
  for (var i = 0; i < wikiPreview.length; i++) {
    if (document.location.href.indexOf(wikiPreview[i]) != -1)
      unique_url = 'wikiPreview';
  }
  var element_id = unique_url ? unique_url : 'bodyContent';
  document.getElementById(element_id).innerHTML = 
    document.getElementById(element_id).innerHTML.replace(/(\d{1,2}) ([A-Z][a-z]+),? (\d{4})/g, adjust_time);

  document.getElementById(element_id).innerHTML = 
    document.getElementById(element_id).innerHTML.replace(/([A-Z][a-z]+) (\d{1,2}), (\d{4})/g, adjust_time_b);

});

function adjust_time(str, old_day, old_month, old_year,s) {
  return old_year + '-' + monArray[old_month] + '-' + old_day;
}

function adjust_time_b(str, old_month, old_day, old_year,s) {
  return old_year + '-' + monArray[old_month] + '-' + old_day;
}