User:小躍/tools/CatTopicInYearEditor.js

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

if(mw.config.get('wgNamespaceNumber') ==='14'){//判斷開始
//start First function
mw.loader.using(['jquery.ui'], function() {
	function CatTopicInYearEditPage( tracePage,destinationPage,edittext,editsummary,linkTo) {
	var api = new mw.Api();
	api.get( {
		'action' : 'query',
		'titles' : tracePage,
		'prop'   : 'revisions|info',
		'intoken' : 'edit',
		'rvprop' : 'content',
		'indexpageids' : 1
	} ).done( function (result) {
		result = result.query;
		var page = result.pages[result.pageids[0]];
	
		api.post( {
			'action' : 'edit',
			'title' : destinationPage,
			'prependtext' :edittext+"\n",
			'minor':1,
			'summary' :editsummary,
			'token' : page.edittoken
		} ).done( function () {
			window.location.href = linkTo;
		} );
	} );
}
wgAction=mw.config.get('wgAction');
wgPageName=mw.config.get('wgPageName');
if ((wgAction == 'edit' || wgAction == 'submit') && wgServer == '//zh.wikipedia.org'&& wgPageName.match("年")) {
    $('#wpDiff').after('\n<input id="wpCatTopicInYearEditButton" value="年度分類主題模板編輯器" title="添加年度分類主題模板(cat topic in year)。" type="button"/>');
    $('#wpCatTopicInYearEditButton').click(CatTopicInYearEdit);
}
var Year=wgPageName.replace(/\D/g,'');
var R1=wgPageName.replace(/[^\D]/g,'');
var CatTopic=R1.replace(/[年]/g,'').substring(9);


function CatTopicInYearEdit(event) {
	event.preventDefault();
	$('<div id="CatTopicInYearEdit" title="年度分類主題模板編輯器">' +
	 '<label>年度:'+Year+'</label><br/>'+
	 '<label>主題:'+CatTopic+'</label><br/>'+
	 '<input id="wpCatTopicInYearSave" value="添加分類主題模板" title="儲存您所添加的分類主題模板。" type="button"/>'+
     '</div>'
     ).dialog({
        modal: false,
        autoOpen: true,
        width: 500
    });
    $('#wpCatTopicInYearSave').click(CatTopicInYearSave);
    document.onkeydown=function(event){
  var e = event || window.event || arguments.callee.caller.arguments[0];
   if(e && e.keyCode==13){ // enter 键
     CatTopicInYearSave;
  }
};
}
function CatTopicInYearSave(event) {
	event.preventDefault();
	CatTopicInYearEditPage( wgPageName,wgPageName,'{{Cat topic in year| topic='+CatTopic+'|year='+Year+'}}','半自動快速添加[[T:Cat topic in year|年度分類主題]]模板。分類主題:'+CatTopic+',年度:'+Year+'<!--Using [[User:小躍/tools/CatTopicInYearEditor.js|CatTopicInYearEditor]]-->',mw.util.getUrl(wgPageName)); 
	$('<div id="CatTopicInYearSaveDone" title="編輯已儲存">' +
      '<img src="http://upload.wikimedia.org/wikipedia/commons/4/42/Loading.gif" /><label>正在添加年度分類主題的模板,請稍後......</label><br/>' +
      '</div>'
     ).dialog({
        modal: false,
        autoOpen: true,
        width: 500
    });
}
//end First function
});
}//判斷結束