跳转到内容

User:Date delinker/bold dates.js

维基百科,自由的百科全书
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google ChromeFirefoxMicrosoft EdgeSafari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
function make_dates_bold(){
 var txt=document.editform.wpTextbox1;

//process date ranges containing a hyphen '* month dd - month dd:'
 txt.value=txt.value.replace(/\*\s?((?:January|February|March|April|May|June|July|August|September|October|November|December) \d\d?\s?[-–]\s?(?:January|February|March|April|May|June|July|August|September|October|November|December) \d\d?)\s?:\s?/gi, '* \'\'\'$1:\'\'\' ');

//process date ranges containing a hyphen '* month dd dd:'
 txt.value=txt.value.replace(/\*\s?((?:January|February|March|April|May|June|July|August|September|October|November|December) \d\d?\s?[-–]\s?\d\d?)\s?:\s?/gi, '* \'\'\'$1:\'\'\' ');

//protect date ranges containing a hyphen
 txt.value=txt.value.replace(/\*\s?((?:January|February|March|April|May|June|July|August|September|October|November|December) \d\d?\s?)[-–](\s?(?:January|February|March|April|May|June|July|August|September|October|November|December) \d\d?)\s?:\s?/gi, '$1xx$2');
 txt.value=txt.value.replace(/\*\s?((?:January|February|March|April|May|June|July|August|September|October|November|December) \d\d?\s?)[-–](\s?\d\d?)\s?:\s?/gi, '$1xx$2');

//process dates containing a hyphen
 txt.value=txt.value.replace(/\*\s?((?:January|February|March|April|May|June|July|August|September|October|November|December) \d\d?\s?)[-–]\s?/gi, '* \'\'\'$1:\'\'\' ');

//unprotect date ranges containing a hyphen
 txt.value=txt.value.replace(/\*\s?((?:January|February|March|April|May|June|July|August|September|October|November|December) \d\d?\s?)xx(\s?(?:January|February|March|April|May|June|July|August|September|October|November|December) \d\d?)\s?:\s?/gi, '$1–$2');
 txt.value=txt.value.replace(/\*\s?((?:January|February|March|April|May|June|July|August|September|October|November|December) \d\d?\s?)xx(\s?\d\d?)\s?:\s?/gi, '$1–$2');

//process other dates
 txt.value=txt.value.replace(/\*\s?((?:January|February|March|April|May|June|July|August|September|October|November|December)\s\d\d?(?:,\s?\d{1,4})?\s?[-–—:])\s/gi, '* \'\'\'$1\'\'\' ');
 txt.value=txt.value.replace(/\*\s?(\d\d?\s(?:January|February|March|April|May|June|July|August|September|October|November|December)(?:\s\d{1,4})?\s?[-–—:])\s/gi, '* \'\'\'$1\'\'\' ');

// edit_summary();
}

$(function () {
 if(document.forms.editform) {
  mw.util.addPortletLink('p-tb', 'javascript:make_dates_bold()', 'Make dates bold', 'ca-unitfixer', 'Fixes some unit formatting', '', '');
  }
});