Jump to content

User:Wyang/autoLoad.js

From Wiktionary, the free dictionary

Note: You may have to bypass your browser’s cache to see the changes. In addition, after saving a sitewide CSS file such as MediaWiki:Common.css, it will take 5-10 minutes before the changes take effect, even if you clear your cache.

  • Mozilla / Firefox / Safari: hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Command-R on a Macintosh);
  • Konqueror and Chrome: click Reload or press F5;
  • Opera: clear the cache in Tools → Preferences;
  • Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5.


function autoLoad() {
	var headingText = document.getElementById("firstHeading").innerHTML;
	
	var re_new = new RegExp("^Creating [^\:]+$");
	var re_allLatin = new RegExp("^Creating [a-zA-Z]+$");
	
	var re_ja = new RegExp("[ぁ-ゖァ-ヺー]");
	var re_zh = new RegExp("[一-龯㐀-䶵]");
	var re_vi = new RegExp("[àằầèềìòồờùừỳáắấéếíóốớúứýảẳẩẻểỉỏổởủửỷãẵẫẽễĩõỗỡũữỹạặậẹệịọộợụựỵđ]");
	var re_ko = new RegExp("[ᄀ-ᄒ"+"ᅡ-ᅵ"+"ᆨ-ᇂ"+"ㄱ-ㆎ가-힣]");
	var re_th = new RegExp("[ก-๛]");
	var re_km = new RegExp("[ក-៩]");
	var re_my = new RegExp("[က-႟ꩠ-ꩻ]");
	var re_hi = new RegExp("[ँंअ-ऊएऐओ-घच-झट-नप-रलवशसहा-ूेैो-◌्।-॰ड़ढ़]");
	
	if (re_new.test(headingText)) {
		if (document.getElementById("mw-previewheader") === null) {
			
			if (re_ja.test(headingText)) {
				$('textarea')[0].value = "{{subst:" + "ja-n}}";
				
			} else if (re_zh.test(headingText)) {
				$('textarea')[0].value = "{{subst:" + "zh-n}}";
				
			} else if (re_vi.test(headingText)) {
				$('textarea')[0].value = "{{subst:" + "vi-n}}";
				
			} else if (re_ko.test(headingText)) {
				$('textarea')[0].value = "{{subst:" + "ko-n}}";
				
			} else if (re_th.test(headingText)) {
				$('textarea')[0].value = "{{subst:" + "th-n}}";
				
			} else if (re_km.test(headingText)) {
				$('textarea')[0].value = "{{subst:" + "km-n}}";
				
			} else if (re_my.test(headingText)) {
				$('textarea')[0].value = "{{subst:" + "my-n}}";
				
			} else if (re_hi.test(headingText)) {
				$('textarea')[0].value = "{{subst:" + "hi-n}}";				
				
			//} else if (re_allLatin.test(headingText)) {
			//	$('textarea')[0].value = "==English==";
				
			//} else {
			//	$('textarea')[0].value = "{{subst:" + "-n}}";
			}
		}
	}
	
	$("#wpTextbox1").on('keyup', function(){
	    var n = $(this).val().replace(/deryy/g,'\n\n====Derived terms====\n{{subst:'+'zh-new/der}}');
	    $(this).val(n);
	});
}

autoLoad();