User:Wyang/common.js

From Wiktionary, the free dictionary
Jump to navigation Jump to search

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.

This JavaScript is executed for Wyang on every page load.


//still experimenting, please help fix any error/clumsiness in the code

//importScript('User:Eirikr/edittools.js');
//importScript('User:Wyang/AddAudio.js');
importScript('User:Dixtosa/AjaxEdit.js');
//importScript('User:suzukaze-c/zhDialMap.js');
//importScript('User:Wyang/autoLoad.js');
importScript('User:V111P/PrefLangs.js');

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_zh = new RegExp("[一-龯㐀-䶵]");
	var re_vi = new RegExp("[àằầèềìòồờùừỳáắấéếíóốớúứýảẳẩẻểỉỏổởủửỷãẵẫẽễĩõỗỡũữỹạặậẹệịọộợụựỵđâêô]");
	var re_ko = new RegExp("[ᄀ-ᄒ"+"ᅡ-ᅵ"+"ᆨ-ᇂ"+"ㄱ-ㆎ가-힣]");
	
	if (re_new.test(headingText)) {
		if (document.getElementById("mw-previewheader") === null) {
			
			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_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();