User:Cyde/monobook.js/dates.js: Difference between revisions

Content deleted Content added
Cyde (talk | contribs)
m Fixing grammar
Cyde (talk | contribs)
Copying over latest from Bobblewik
Line 41:
// ranked days
txt.value = txt.value.replace(/\[\[(\d{1,2}(?:st|nd|rd|th))\]\]/gi, '$1');
 
 
// misconfigured
Line 47 ⟶ 46:
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
//BC etc
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');
//4 digitsdigit years piped into 2
txt.value = txt.value.replace(/\[\[\d{1,4}\|(\d{1,2})\]\]/gi, '$1');
 
//year: last character in link on left is not month or digit, first character in link on right is not month or digit
//begin loop because delinking of years needs to run several times
txt.value = txt.value.replace(/([^yhletr\d]\]\]\s?,?\-?\s?)\[\[(\d{1,4})\]\](\s?,?\-?\s?\[\[[^jfmasond\d])/gi, '$1$2$3');
var x=0;
//year pair: last character in link on left is not month or digit, first character in link on right is not month or digit
while (x<5) {
txt.value = txt.value.replace(/([^yhletr\d]\]\]\s?,?\-?\s?)\[\[(\d{1,4})\]\](.?.?.?.?.?.?)\[\[(\d{1,4})\]\](\s?,?\-?\s?\[\[[^jfmasond\d])/gi, '$1$2$3$4$5');
x++;
 
//year: textlast character in link on left is not month or digit, avoid links on right
txt.value = txt.value.replace(/([\w\(\);:.\*\|\&]\s?,?\-?\s?)\[\[(\d{1,4})\]\]([^\[]{4})/gi, '$1$2$3');
txt.value = txt.value.replace(/([^yhletr\d]\]\]\s?,?\-?\s?)\[\[(\d{1,4})\]\]([^\[]{4})/gi, '$1$2$3');
//year pair: last character in link on left is not month or digit, avoid links on right
txt.value = txt.value.replace(/([^yhletr\d]\]\]\s?,?\-?\s?)\[\[(\d{1,4})\]\](.?.?.?.?.?.?)\[\[(\d{1,4})\]\]([^\[]{4})/gi, '$1$2$3$4$5');
 
//year: check for line-ends, text on left, avoid links on right. Run twice to deal better with lists.
txt.value = txt.value.replace(/([\w\(\);:.\*\|\&]\s?,?\-?\s?|\n)\[\[(\d{1,4})\]\]([^\[]{4}|\n)/gi, '$1$2$3');
txt.value = txt.value.replace(/([^\]]{4})w\[\[(\d{1,4});:.\]*\|\&](\s?,?\-?\s?|\n)\[\[(\d{1,4})\]\]([^jfmasond\d[]{4}|\n)/gi, '$1$2$3');
 
//year: avoid links on left, first character in link on right is not month or digit
txt.value = txt.value.replace(/([^\]]{4})\[\[(\d{1,4})\]\](.?.?.?.?.?.?)\[\[(\d{1,4})\]\](\s?,?\-?\s?\[\[[^jfmasond\d])/gi, '$1$2$3$4$5');
//year pair: avoid links on left, first character in link on right is not month or digit
txt.value = txt.value.replace(/([^\]]{4})\[\[(\d{1,4})\]\](.?.?.?.?.?.?)\[\[(\d{1,4})\]\](\s?,?\-?\s?\[\[[^jfmasond\d])/gi, '$1$2$3$4$5');
 
//year pair: text on left, avoid links on right
txt.value = txt.value.replace(/([\w\(\);:.\*\|\&]\s?,?\-?\s?)\[\[(\d{1,4})\]\](.?.?.?.?.?.?)\[\[(\d{1,4})\]\]([^\[]{4})/gi, '$1$2$3$4$5');
Line 72 ⟶ 83:
//year pair: avoid links on both sides
txt.value = txt.value.replace(/([^\]]{4})\[\[(\d{1,4})\]\](.?.?.?.?.?.?)\[\[(\d{1,4})\]\]([^\[]{4})/gi, '$1$2$3$4$5');
 
//year: last character in link on left is not month or digit, avoid links on right
txt.value = txt.value.replace(/([^yhletr\d]\]\]\s?,?\-?\s?)\[\[(\d{1,4})\]\]([^\[]{4})/gi, '$1$2$3');
//year pair: last character in link on left is not month or digit, avoid links on right
txt.value = txt.value.replace(/([^yhletr\d]\]\]\s?,?\-?\s?)\[\[(\d{1,4})\]\](.?.?.?.?.?.?)\[\[(\d{1,4})\]\]([^\[]{4})/gi, '$1$2$3$4$5');
 
//year: avoid links on left, first character in link on right is not month or digit
txt.value = txt.value.replace(/([^\]]{4})\[\[(\d{1,4})\]\](\s?,?\-?\s?\[\[[^jfmasond\d])/gi, '$1$2$3');
//year pair: avoid links on left, first character in link on right is not month or digit
txt.value = txt.value.replace(/([^\]]{4})\[\[(\d{1,4})\]\](.?.?.?.?.?.?)\[\[(\d{1,4})\]\](\s?,?\-?\s?\[\[[^jfmasond\d])/gi, '$1$2$3$4$5');
 
//year: last character in link on left is not month or digit, first character in link on right is not month or digit
txt.value = txt.value.replace(/([^yhletr\d]\]\]\s?,?\-?\s?)\[\[(\d{1,4})\]\](\s?,?\-?\s?\[\[[^jfmasond\d])/gi, '$1$2$3');
//year pair: last character in link on left is not month or digit, first character in link on right is not month or digit
txt.value = txt.value.replace(/([^yhletr\d]\]\]\s?,?\-?\s?)\[\[(\d{1,4})\]\](.?.?.?.?.?.?)\[\[(\d{1,4})\]\](\s?,?\-?\s?\[\[[^jfmasond\d])/gi, '$1$2$3$4$5');
//end of loop
}
 
 
// Add a tag to the summary box
Line 107 ⟶ 100:
addOnloadHook(function () {
if(document.forms.editform) {
addLink('p-cactions', 'javascript:formatdates()', 'dates2datestest', 'ca-datefixer', 'Fixes some date formatting', '', '');
}
});