User:Cdip150/工具/介面/ConvertRefNoteTag.js

注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google ChromeFirefoxMicrosoft EdgeSafari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
// <nowiki>
$(function(){
	if(mw.config.get("wgAction")!="submit") return;
	location.replace("#references-NoteFoot");
});

$( function(){
	var $editform=$("#editform");
	var $wpTextbox1=$editform.find("#wpTextbox1"), wpTextbox1=$wpTextbox1.get(0);
	
	if($wpTextbox1.length*$editform.find("#wpSave").length===0) return;
	
	var $btnBigSave=$("<input />", {
		name:"btnBigSave",
		id:"btnBigSave",
		type:"button",
		value:"Save"
	}).click(function(){
		$editform.find("#wpSave").click();
	}).css({
		"font-size":"36pt",
		"position":"fixed",
		"left":0,
		"bottom":0
	});
	$("body").eq(0).append($btnBigSave);
	
	var $pos=$("<span />").insertAfter($wpTextbox1);
	
	var setSum=function(){
		//$editform.find("#wpSummary").get(0).value="修正參註分組,避免混淆及小工具與技術出錯";
	};
	
	var chknote=function(){
		var v=wpTextbox1.value;

		var str="";
		var addln=function(s){str+=s+"\n"};
		
		if(v.match(/\<\s*?ref(\s+?name\s*?\=\s*?\S+?)?\s*?\>/ig)) addln("\<ref\>");
		if(v.match(/\<\s*?ref\s+?[^>]*?group\s*?\=\s*?[\"\'][註注][\"\'][^>]*?\>/ig)) addln('\<ref group=\"註\"\>');
		if(v.match(/\{\{\s*?(?:refTag|[參参]考?)\s*?\|/ig)) addln('\{\{refTag\}\}');
		if(v.match(/\{\{\s*?(?:refFoot|[參参]表[腳脚])/ig)) addln('\{\{refFoot\}\}');
		if(v.match(/\{\{\s*?(?:noteTag|[備备]?[註注])\s*?\|/ig)) addln('\{\{noteTag\}\}');
		if(v.match(/\{\{\s*?(?:noteFoot|[註注]表[腳脚])/ig)) addln('\{\{noteFoot\}\}');
		if(v.match(/\{\{\s*?efn\s*?\|/ig)) addln('\{\{efn\}\}');
		if(v.match(/\{\{\s*?reflist/ig)) addln('\{\{reflist\}\}');
		if(v.match(/\{\{\s*?notelist/ig)) addln('\{\{notelist\}\}');
		if(v.match(/\<\s*?references/ig)) addln('\<references \/\>');

		if(str!="") if(window.confirm(str)) setTimeout(function(){
			$refhtml2reftag.click();
			$notehtml2notetag.click();
			$efn2notetag.click();
			$notelist2notefoot.click();
			$reflistnote2notefoot.click();
			$reflist2reffoot.click();
			
			$editform.find("#wpPreview").click();
		},100);
	};
	//if(mw.config.get("wgAction")=="edit") chknote();
	
	var $btnCheck=$("<input />", {
		name:"btnCheck",
		id:"btnCheck",
		type:"button",
		value:"檢查"
	}).click(chknote).insertBefore($pos);
	
	
	
	var $refhtml2refgt=$("<input />", {
		name:"refhtml2refgt",
		id:"refhtml2refgt",
		type:"button",
		value:"\<ref\>→\{\{refGT\}\}"
	}).click(function(){
		setSum();
		var str=wpTextbox1.value;
		
		str=str.replace(/\<\s*?ref\s*?\>((?:.|\n)*?)\<\s*?\/ref\s*?\>/ig, "\{\{refGT\|1\=$1\}\}");
		str=str.replace(/\<\s*?ref\s+?name\s*?\=\s*?[\"\']?([^\"\'\>]*?)[\"\']?\s*?\/\>/ig, "\{\{refGT\|name\=$1\}\}");
		str=str.replace(/\<\s*?ref\s+?name\s*?\=\s*?[\"\']?([^\"\'\>]*?)[\"\']?\s*?\>((?:.|\n)*?)\<\s*?\/ref\s*?\>/ig, "\{\{refGT\|name\=$1\|1\=$2\}\}");
		
		wpTextbox1.value=str;
	}).insertBefore($pos);
	
	var $notehtml2notegt=$("<input />", {
		name:"btnConvertNotegt",
		id:"btnConvertNotegt",
		type:"button",
		value:"註→\{\{noteGT\}\}"
	}).click(function(){
		setSum();
		var str=wpTextbox1.value;

		str=str.replace(/\<\s*?ref\s+?group\s*?\=\s*?[\"\']?[註注][\"\']?\s*?\>((?:.|\n)*?)\<\s*?\/ref\s*?\>/ig, "\{\{noteGT\|1\=$1\}\}");
		str=str.replace(/\<\s*?ref\s+?group\s*?\=\s*?[\"\']?[註注][\"\']?\s+?name\s*?\=\s*?[\"\']?([^\"\'\>]*?)[\"\']?\s*?\/\>/ig, "\{\{noteGT\|name\=$1\}\}");
		str=str.replace(/\<\s*?ref\s+?group\s*?\=\s*?[\"\']?[註注][\"\']?\s+?name\s*?\=\s*?[\"\']?([^\"\'\>]*?)[\"\']?\s*?\>((?:.|\n)*?)\<\s*?\/ref\s*?\>/ig, "\{\{noteGT\|name\=$1\|1\=$2\}\}");
		str=str.replace(/\<\s*?ref\s+?name\s*?\=\s*?[\"\']?([^\"\'\>]*?)[\"\']?\s+?group\s*?\=\s*?[\"\']?[註注][\"\']?\s*?\/\>/ig, "\{\{noteGT\|name\=$1\}\}");
		str=str.replace(/\<\s*?ref\s+?name\s*?\=\s*?[\"\']?([^\"\'\>]*?)[\"\']?\s+?group\s*?\=\s*?[\"\']?[註注][\"\']?\s*?\>((?:.|\n)*?)\<\s*?\/ref\s*?\>/ig, "\{\{noteGT\|name\=$1\|1\=$2\}\}");
		
		wpTextbox1.value=str;
	}).insertBefore($pos);
	
	var $efn2notegt=$("<input />", {
		name:"efn2notegt",
		id:"efn2notegt",
		type:"button",
		value:"\{\{efn\}\}→\{\{noteGT\}\}"
	}).click(function(){
		setSum();
		var str=wpTextbox1.value;

		str=str.replace(/\{\{\s*?efn\s*?\|/ig, "\{\{noteGT\|");
		
		wpTextbox1.value=str;
	}).insertBefore($pos);
	
	var $notehtml2efn=$("<input />", {
		name:"notehtml2efn",
		id:"notehtml2efn",
		type:"button",
		value:"註→\{\{efn\}\}"
	}).click(function(){
		setSum();
		var str=wpTextbox1.value;

		str=str.replace(/\<\s*?ref\s+?group\s*?\=\s*?[\"\']?[註注][\"\']?\s*?\>((?:.|\n)*?)\<\s*?\/ref\s*?\>/ig, "\{\{efn\|1\=$1\}\}");
		str=str.replace(/\<\s*?ref\s+?group\s*?\=\s*?[\"\']?[註注][\"\']?\s+?name\s*?\=\s*?[\"\']?([^\"\'\>]*?)[\"\']?\s*?\/\>/ig, "\{\{efn\|name\=$1\}\}");
		str=str.replace(/\<\s*?ref\s+?group\s*?\=\s*?[\"\']?[註注][\"\']?\s+?name\s*?\=\s*?[\"\']?([^\"\'\>]*?)[\"\']?\s*?\>((?:.|\n)*?)\<\s*?\/ref\s*?\>/ig, "\{\{efn\|name\=$1\|1\=$2\}\}");
		str=str.replace(/\<\s*?ref\s+?name\s*?\=\s*?[\"\']?([^\"\'\>]*?)[\"\']?\s+?group\s*?\=\s*?[\"\']?[註注][\"\']?\s*?\/\>/ig, "\{\{efn\|name\=$1\}\}");
		str=str.replace(/\<\s*?ref\s+?name\s*?\=\s*?[\"\']?([^\"\'\>]*?)[\"\']?\s+?group\s*?\=\s*?[\"\']?[註注][\"\']?\s*?\>((?:.|\n)*?)\<\s*?\/ref\s*?\>/ig, "\{\{efn\|name\=$1\|1\=$2\}\}");
		
		wpTextbox1.value=str;
	}).insertBefore($pos);
	
	var $notetag2efn=$("<input />", {
		name:"notetag2efn",
		id:"notetag2efn",
		type:"button",
		value:"\{\{noteTag\}\}→\{\{efn\}\}"
	}).click(function(){
		setSum();
		var str=wpTextbox1.value;

		str=str.replace(/\{\{\s*?(?:noteTag|[備备]?[註注])\s*?\|/ig, "\{\{efn\|");
		
		wpTextbox1.value=str;
	}).insertBefore($pos);
	
	var $notetag2notegt=$("<input />", {
		name:"notetag2notegt",
		id:"notetag2notegt",
		type:"button",
		value:"\{\{noteTag\}\}→\{\{noteGT\}\}"
	}).click(function(){
		setSum();
		var str=wpTextbox1.value;

		str=str.replace(/\{\{\s*?(?:noteTag|[備备]?[註注])\s*?\|/ig, "\{\{noteGT\|");
		
		wpTextbox1.value=str;
	}).insertBefore($pos);
	
	var $notetag2refgt=$("<input />", {
		name:"reftag2refgt",
		id:"reftag2refgt",
		type:"button",
		value:"\{\{refTag\}\}→\{\{refGT\}\}"
	}).click(function(){
		setSum();
		var str=wpTextbox1.value;

		str=str.replace(/\{\{\s*?(?:refTag|[參参]考?)\s*?\|/ig, "\{\{refGT\|");
		
		wpTextbox1.value=str;
	}).insertBefore($pos);
	
	$("<hr />").insertBefore($pos);
	var $reflist2refgf=$("<input />", {
		name:"reflist2refgf",
		id:"reflist2refgf",
		type:"button",
		value:"\{\{reflist\}\}→\{\{refGF\}\}"
	}).click(function(){
		setSum();
		var str=wpTextbox1.value;

		str=str.replace(/\{\{\s*?reflist\s*?\}\}/ig, "\{\{refGF\}\}");
		str=str.replace(/\{\{\s*?reflist\s*?\|\s*?\d*/ig, "\{\{refGF\|");
		str=str.replace(/\<\s*?references\s*?\/\>/ig, "\{\{refGF\|=\}\}");
		str=str.replace(/\<\s*?references\s*?\>((?:.|\n)*?)\<\s*?\/references\s*?\>/ig, "\{\{refGF\|1\=$1\}\}");
		
		wpTextbox1.value=str;
	}).insertBefore($pos);
	
	var $notelist2notegf=$("<input />", {
		name:"notelist2notegf",
		id:"notelist2notegf",
		type:"button",
		value:"\{\{notelist\}\}→\{\{noteGF\}\}"
	}).click(function(){
		setSum();
		var str=wpTextbox1.value;
		
		str=str.replace(/\{\{\s*?notelist(?:\s*?\|\s*?\d*)?/ig, "\{\{noteGF\|");
		
		wpTextbox1.value=str;
	}).insertBefore($pos);
	
	var $notefoot2notelist=$("<input />", {
		name:"notefoot2notelist",
		id:"notefoot2notelist",
		type:"button",
		value:"\{\{noteFoot\}\}→\{\{notelist\}\}"
	}).click(function(){
		setSum();
		var str=wpTextbox1.value;

		str=str.replace(/\{\{\s*?(?:noteFoot|[註注]表[腳脚])/ig, "\{\{notelist");
		
		wpTextbox1.value=str;
	}).insertBefore($pos);
	
	var $reflistnote2notegf=$("<input />", {
		name:"reflistnote2notegf",
		id:"reflistnote2notegf",
		type:"button",
		value:"\{\{reflist|group=註\}\}→\{\{noteGF\}\}"
	}).click(function(){
		setSum();
		var str=wpTextbox1.value;

		str=str.replace(/\{\{\s*?reflist\s*?\|(?:\s+?\d\s*?\|)?\s*?group\s*?\=\s*?[\"\']?[註注][\"\']?/ig, "\{\{noteGF\|");
		str=str.replace(/\<\s*?references\s+?group\s*?\=\s*?[\"\']?[註注][\"\']?\s*?\/\>/ig, "\{\{noteGF\|\}\}");
		str=str.replace(/\<\s*?references\s+?group\s*?\=\s*?[\"\']?[註注][\"\']?\s*?\>((?:.|\n)*?)\<\s*?\/references\s*?\>/ig, "\{\{noteGF\|1\=$1\}\}");
		
		wpTextbox1.value=str;
	}).insertBefore($pos);
	
	var $reflistnote2notelist=$("<input />", {
		name:"reflistnote2notelist",
		id:"reflistnote2notelist",
		type:"button",
		value:"\{\{reflist|group=註\}\}→\{\{notelist\}\}"
	}).click(function(){
		setSum();
		var str=wpTextbox1.value;

		str=str.replace(/\{\{\s*?reflist\s*?\|(?:\s+?\d\s*?\|)?\s*?group\s*?\=\s*?[\"\']?[註注][\"\']?/ig, "\{\{notelist");
		str=str.replace(/\<\s*?references\s+?group\s*?\=\s*?[\"\']?[註注][\"\']?\s*?\/\>/ig, "\{\{notelist\}\}");
		str=str.replace(/\<\s*?references\s+?group\s*?\=\s*?[\"\']?[註注][\"\']?\s*?\>((?:.|\n)*?)\<\s*?\/references\s*?\>/ig, "\{\{notelist\|1\=$1\}\}");
		
		wpTextbox1.value=str;
	}).insertBefore($pos);
	
	var $reffoot2refgf=$("<input />", {
		name:"reffoot2refgf",
		id:"reffoot2refgt",
		type:"button",
		value:"\{\{refFoot\}\}→\{\{refGF\}\}"
	}).click(function(){
		setSum();
		var str=wpTextbox1.value;

		str=str.replace(/\{\{\s*?(?:refFoot|[參参]表[腳脚])/ig, "\{\{refGF");
		
		wpTextbox1.value=str;
	}).insertBefore($pos);
		
	var $notefoot2notegf=$("<input />", {
		name:"notefoot2notegf",
		id:"notefoot2notegf",
		type:"button",
		value:"\{\{noteFoot\}\}→\{\{noteGF\}\}"
	}).click(function(){
		setSum();
		var str=wpTextbox1.value;

		str=str.replace(/\{\{\s*?(?:noteFoot|[註注]表[腳脚])/ig, "\{\{noteGF");
		
		wpTextbox1.value=str;
	}).insertBefore($pos);
	
	$("<hr />").insertBefore($pos);
	var $anytag2refgt=$("<input />", {
		name:"anytag2refgt",
		id:"anytag2refgt",
		type:"button",
		value:"...→\{\{refGT\}\}"
	}).click(function(){
		setSum();
		var str=wpTextbox1.value;

		var patt=prompt("RegExp","");

		str=str.replace(new RegExp("\\<\\s*?ref\\s+?group\\s*?\\=\\s*?[\\\"\\\']?"+patt+"[\\\"\\\']?\\s*?\\>((?:.|\\n)*?)\\<\\s*?\\/ref\\s*?\\>", "ig"), "\{\{refGT\|1\=$1\}\}");
		str=str.replace(new RegExp("\\<\\s*?ref\\s+?group\\s*?\\=\\s*?[\\\"\\\']?"+patt+"[\\\"\\\']?\\s+?name\\s*?\\=\\s*?[\\\"\\\']?([^\\\"\\\']*?)[\\\"\\\']?\\s*?\\/\\>", "ig"), "\{\{refGT\|name\=$1\}\}");
		str=str.replace(new RegExp("\\<\\s*?ref\\s+?group\\s*?\\=\\s*?[\\\"\\\']?"+patt+"[\\\"\\\']?\\s+?name\\s*?\\=\\s*?[\\\"\\\']?([^\\\"\\\']*?)[\\\"\\\']?\\s*?\\>((?:.|\\n)*?)\\<\\s*?\\/ref\\s*?\\>", "ig"), "\{\{refGT\|name\=$1\|1\=$2\}\}");
		str=str.replace(new RegExp("\\<\\s*?ref\\s+?name\\s*?\\=\\s*?[\\\"\\\']?([^\\\"\\\']*?)[\\\"\\\']?\\s+?group\\s*?\\=\\s*?[\\\"\\\']?"+patt+"[\\\"\\\']?\\s*?\\/\\>", "ig"), "\{\{refGT\|name\=$1\}\}");
		str=str.replace(new RegExp("\\<\\s*?ref\\s+?name\\s*?\\=\\s*?[\\\"\\\']?([^\\\"\\\']*?)[\\\"\\\']?\\s+?group\\s*?\\=\\s*?[\\\"\\\']?"+patt+"[\\\"\\\']?\\s*?\\>((?:.|\\n)*?)\\<\\s*?\\/ref\\s*?\\>", "ig"), "\{\{refGT\|name\=$1\|1\=$2\}\}");

		
		wpTextbox1.value=str;
	}).insertBefore($pos);
	
	var $anytag2notegt=$("<input />", {
		name:"anytag2notegt",
		id:"anytag2notegt",
		type:"button",
		value:"...→\{\{noteGT\}\}"
	}).click(function(){
		setSum();
		var str=wpTextbox1.value;

		var patt=prompt("RegExp","");

		str=str.replace(new RegExp("\\<\\s*?ref\\s+?group\\s*?\\=\\s*?[\\\"\\\']?"+patt+"[\\\"\\\']?\\s*?\\>((?:.|\\n)*?)\\<\\s*?\\/ref\\s*?\\>", "ig"), "\{\{noteGT\|1\=$1\}\}");
		str=str.replace(new RegExp("\\<\\s*?ref\\s+?group\\s*?\\=\\s*?[\\\"\\\']?"+patt+"[\\\"\\\']?\\s+?name\\s*?\\=\\s*?[\\\"\\\']?([^\\\"\\\']*?)[\\\"\\\']?\\s*?\\/\\>", "ig"), "\{\{noteGT\|name\=$1\}\}");
		str=str.replace(new RegExp("\\<\\s*?ref\\s+?group\\s*?\\=\\s*?[\\\"\\\']?"+patt+"[\\\"\\\']?\\s+?name\\s*?\\=\\s*?[\\\"\\\']?([^\\\"\\\']*?)[\\\"\\\']?\\s*?\\>((?:.|\\n)*?)\\<\\s*?\\/ref\\s*?\\>", "ig"), "\{\{noteGT\|name\=$1\|1\=$2\}\}");
		str=str.replace(new RegExp("\\<\\s*?ref\\s+?name\\s*?\\=\\s*?[\\\"\\\']?([^\\\"\\\']*?)[\\\"\\\']?\\s+?group\\s*?\\=\\s*?[\\\"\\\']?"+patt+"[\\\"\\\']?\\s*?\\/\\>", "ig"), "\{\{noteGT\|name\=$1\}\}");
		str=str.replace(new RegExp("\\<\\s*?ref\\s+?name\\s*?\\=\\s*?[\\\"\\\']?([^\\\"\\\']*?)[\\\"\\\']?\\s+?group\\s*?\\=\\s*?[\\\"\\\']?"+patt+"[\\\"\\\']?\\s*?\\>((?:.|\\n)*?)\\<\\s*?\\/ref\\s*?\\>", "ig"), "\{\{noteGT\|name\=$1\|1\=$2\}\}");
		
		wpTextbox1.value=str;
	}).insertBefore($pos);
	
	var $anylist2notegf=$("<input />", {
		name:"anylist2notegf",
		id:"anylist2notegf",
		type:"button",
		value:"...→\{\{noteGF\}\}"
	}).click(function(){
		setSum();
		var str=wpTextbox1.value;

		var patt=prompt("RegExp","");
		
		str=str.replace(new RegExp("\\{\\{\\s*?reflist\\s*?\\|(?:\\s+?\\d\\s*?\\|)?\\s*?group\\s*?\\=\\s*?"+patt,"ig"), "\{\{noteGF");
		str=str.replace(new RegExp("\\<references\\s+?group\\s*?\\=\\s*?[\\\"\\\']"+patt+"[\\\"\\\']\\s*?\\/\\>","ig"), "\{\{noteGF\}\}");
		str=str.replace(new RegExp("\\<references\\s+?group\\s*?\\=\\s*?[\\\"\\\']"+patt+"[\\\"\\\']\\s*?\\>((?:.|\\n)*?)\\<\\s*?\\/references\\s*?\\>","ig"), "\{\{noteGF\|1\=$1\}\}");
		
		wpTextbox1.value=str;
	}).insertBefore($pos);
	
	
	$("<hr />").insertBefore($pos);
	var $substreftag=$("<input />", {
		name:"substreftag",
		id:"substreftag",
		type:"button",
		value:"subst:refTag"
	}).click(function(){
		setSum();
		var str=wpTextbox1.value;

		var grp=prompt("group","");
		
		str=str.replace(new RegExp("\\{\\{\\s*?(?:refTag|[參参]考?)\\s*?\\|", "ig"), "\{\{sub"+"st:refTag\|subst=subst:\|group\="+grp+"\|iger=\|");
		
		wpTextbox1.value=str;
	}).insertBefore($pos);
	
	var $substnotetag=$("<input />", {
		name:"substnotetag",
		id:"substnotetag",
		type:"button",
		value:"subst:noteTag"
	}).click(function(){
		setSum();
		var str=wpTextbox1.value;

		var grp=prompt("group","");
		
		str=str.replace(new RegExp("\\{\\{\\s*?(?:noteTag|[備备]?[註注])\\s*?\\|", "ig"), "\{\{sub"+"st:noteTag\|subst=subst:\|group\="+grp+"\|iger=\|");
		
		wpTextbox1.value=str;

	}).insertBefore($pos);
	
});
// </nowiki>