User:Zestwiki/luna-format.js

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

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

//			伊州古調 唱出繞樑聲
//		果然是藝苑專精 風月叢中第一名
//-----------------------------------------------------------------//
/* 
巡查者可使用  importScript('User:Zestwiki/luna-format.js'); 協助測試
有問題回報會修正


已知問題,有角度使用"可能會消失。
已知問題,{{tsl}}裡面會直接轉換<測試修正中
-----------------------------------------------------------------
基本格式取代
尋找[ ()],不轉換
尋找()>( )轉換暴力轉換,包括參考文獻
     備取方式,"轉換成 「 」但可能會有問題
尋找<sup>3</sup>
	轉換立方千米


*/


//包含多餘函數
if  ($.inArray(mw.config.get('wgAction'), ['edit', 'submit']) !== -1) 
    {$.ajax('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js',
        {dataType:'script', cache:true 
    }).done( function() 
        {$.when(mw.loader.using( ['mediawiki.util']),
	 $.ajax('//en.wikipedia.org/w/index.php?title=User:Ohconfucius/script/MOSNUM_utils.js&action=raw&ctype=text/javascript',
        { dataType:'script', cache:true 
        }),
         $.ready).done( function() 
        {var add = mw.util.addPortletLink;
	 $(add('p-tb','#','luna_format','','修正月球','','')).click(luna_fix_a);
        });
	});
}

function luna_fix_a(e) 
    {
	e.preventDefault();
	luna_fix();
	edit_summary('lllu');
    }
var summary = 
    {
    luna_fix:wgULS('[[User:Zestwiki/luna-format.js|测试版标点修正]]','[[User:Zestwiki/luna-format.js|測試版標點修正]]'),
    };
function check(type) 
    {if (type == 'lllu') 
        {return summary.luna_fix;
        }
    }
function luna_fix() 
    {
    var edd = $('#wpTextbox1'), text = edd.val();
	text = text.replace(/\"/gi,'');//全部 " 暴力消失
	text = text.replace(/\(/gi,'(');
	text = text.replace(/\)/gi,')');//智障暴力
	text = text.replace(/\[\[([^\]]*\s)\(([^\]]*)\)([\|]*[^\]]*)\]\]/gi,'[['+'$1'+'('+'$2'+')'+'$3'+']]');//可能不能匹配IMG裡面的、可能不能處理[[xxx|xx (0)]<應沒有這樣的格式
	text = text.replace(/{{([^\}]*\s?)\(([^\}]*)\)([\|]*[^\}]*|)}}/gi,'{{'+'$1'+'('+'$2'+')'+'$3'+'}}');
	text = text.replace(/\[\[([^\]]*\s)\(([^\]]*)\)([\|]*[^\]]*)\]\]/gi,'[['+'$1'+'('+'$2'+')'+'$3'+']]');//暴力*2
	text = text.replace(/{{([^\}]*\s?)\(([^\}]*)\)([\|]*[^\}]*|)}}/gi,'{{'+'$1'+'('+'$2'+')'+'$3'+'}}');
	text = text.replace('公里<sup>3</sup>','立方千米');	
	edd.val(text);
    }
function edit_summary(type) 
    {
	setoptions(minor='true');
	setreason(check(type), 'append');
	doaction('diff');//差異預覽
    }