Jump to content

User:Sligocki/unlinkdates.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.
// Unlinks linked dates in an article. Some dates are linked for a reason, check after yourself.
function autoEdUnlinkDates(str) {
  
  // [[October 21]], [[2007]]
  str = str.replace(/\[\[(January|February|March|April|May|June|July|August|September|October|November|December)\s+([0-3]?\d)\]\],?\s+\[\[(\d\d\d\d)\]\]/gi, '$1 $2, $3');
  
  // [[21 October]] [[2007]]
  str = str.replace(/\[\[([0-3]?\d)\s+(January|February|March|April|May|June|July|August|September|October|November|December)\]\],?\s+\[\[(\d\d\d\d)\]\]/gi, '$1 $2 $3');
  
  // [[2007-10-21]]
  str = str.replace(/\[\[(\d\d\d\d\-\d\d\-\d\d)\]\]/gi, '$1');
  
  // [[2007]]-[[10-21]]
  str = str.replace(/\[\[(\d\d\d\d)\]\]\-\[\[(\d\d\-\d\d)\]\]/gi, '$1-$2');
  
  // [[October 21]]
  str = str.replace(/\[\[(January|February|March|April|May|June|July|August|September|October|November|December)\s+([0-3]?\d)\]\]/gi, '$1 $2');
  
  // [[October 21|21]]
  str = str.replace(/\[\[(January|February|March|April|May|June|July|August|September|October|November|December)\s+([0-3]?\d)\|\2\]\]/gi, '$2');
  
  // [[21 October]]
  str = str.replace(/\[\[([0-3]?\d)\s+(January|February|March|April|May|June|July|August|September|October|November|December)\]\]/gi, '$1 $2');
  
  // [[21 October|21]]
  str = str.replace(/\[\[([0-3]?\d)\s+(January|February|March|April|May|June|July|August|September|October|November|December)\|\1\]\]/gi, '$1');
  
  // [[2007]]
  str = str.replace(/\[\[(\d\d\d\d)\]\]/gi, '$1');
  
  // [[2007|07]]
  // str = str.replace(/\[\[(\d\d)(\d\d)\|\2\]\]/gi, '$2');
  
  // [[October 2007]]
  str = str.replace(/\[\[(January|February|March|April|May|June|July|August|September|October|November|December)\s+(\d\d\d\d)\]\]/gi, '$1 $2');
  
  return str;
}

//