User:StevenK234/Tools/Datesfixer.js

维基百科,自由的百科全书

注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google ChromeFirefoxMicrosoft EdgeSafari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。

//基於[[WP:格式手冊/日期和數字]]「2.1.1 公元紀年」中的指引:「公元紀年以年月日表示時,不加上不必要的零」。
$.ajax('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js', { dataType:'script', cache:true }).then(function() {
			$(function() {
				var add = mw.util.addPortletLink;
				$( add('p-tb', '#', '清理錯誤日期格式', 'T-DF', '清除錯誤的日期格式', '', '') ).click(Dates_driver);
			});
});

function Dates_fixed(){
$(document).ready(function() {
	strOld=$('#wpTextbox1').val();
	strNew=Dates_replace(strOld);
	$('#wpTextbox1').val(strNew);
	strOld=DF_edit_summary(strOld);
	$('#wpTextbox1').val(strNew);
 });
}

function Dates_replace(RE){
	var number1 = /\u0030(\d)月/g;
	var number2 = /\u0030(\d)日/g;
	var number3 = /(\年|\月)\u0030(\d)/g;
	do{RE=RE.replace(number1,'$1月');}while(RE.indexOf(number1)!=-1);
	do{RE=RE.replace(number2,'$1日');}while(RE.indexOf(number2)!=-1);
	do{RE=RE.replace(number3,'$1$2');}while(RE.indexOf(number3)!=-1);
	return RE;
}

function DF_edit_summary() {
	setoptions(minor='true');
	setreason(wgULS('經由[[User:StevenK234/Tools/Datesfixer.js|Datesfixer.js]][[WP:MOSDATE|清理錯誤的日期格式]]。', ''), 'append');
	doaction('diff');
}

function Dates_driver() {
	Dates_fixed();
}