Thai Hotmail

By ooooo Last update Nov 4, 2005 — Installed 1,476 times. Daily Installs: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 1
// ==UserScript==
// @name           Thai Hotmail
// @namespace      urn:rotemliss:greasmonkey:scripts:hotmailthaiencoding
// @description    Make hotmail encoding to Thai
// @include        http://by*fd.bay*.hotmail.msn.com/cgi-bin/HoTMaiL*
// @include        http://by*fd.bay*.hotmail.msn.com/cgi-bin/getmsg*
// @include        http://by*fd.bay*.hotmail.msn.com/cgi-bin/compose*
// @include        http://by*fd.bay*.hotmail.msn.com/cgi-bin/hmhome*
// ==/UserScript==

(function()
{
	
	HTMLElement.prototype.fixEnglishToThai = function()
	{
		//Modify by ooooo - E-mail: stopeat@gmail.com
		//Original code by Rotem Liss and Liron Newman, http://eesh.net
		
		var html = this.innerHTML;
		html = html.replace(/¡/g,"�");
		html = html.replace(/¢/g,"ข");
		html = html.replace(/£/g,"ฃ");
		html = html.replace(/¤/g,"ค");
		html = html.replace(/¥/g,"ฅ");
		html = html.replace(/¦/g,"ฆ");
		html = html.replace(/§/g,"ง");
		html = html.replace(/¨/g,"จ");
		html = html.replace(/©/g,"ฉ");
		html = html.replace(/ª/g,"ช");
		html = html.replace(/«/g,"ซ");
		html = html.replace(/¬/g,"ฌ");
		html = html.replace(/­/g,"�");
		html = html.replace(/®/g,"ฎ");
		html = html.replace(/¯/g,"�");
		html = html.replace(/°/g,"�");
		html = html.replace(/±/g,"ฑ");
		html = html.replace(/²/g,"ฒ");
		html = html.replace(/³/g,"ณ");
		html = html.replace(/´/g,"ด");
		html = html.replace(/µ/g,"ต");
		html = html.replace(/¶/g,"ถ");
		html = html.replace(/·/g,"ท");
		html = html.replace(/¸/g,"ธ");
		html = html.replace(/¹/g,"น");
		html = html.replace(/º/g,"บ");
		html = html.replace(/»/g,"ป");
		html = html.replace(/¼/g,"ผ");
		html = html.replace(/½/g,"�");
		html = html.replace(/¾/g,"พ");
		html = html.replace(/¿/g,"ฟ");
		html = html.replace(/À/g,"ภ");
		html = html.replace(/�/g,"ม");
		html = html.replace(/Â/g,"ย");
		html = html.replace(/Ã/g,"ร");
		html = html.replace(/Ä/g,"ฤ");
		html = html.replace(/Å/g,"ล");
		html = html.replace(/Æ/g,"ฦ");
		html = html.replace(/Ç/g,"ว");
		html = html.replace(/È/g,"ศ");
		html = html.replace(/É/g,"ษ");
		html = html.replace(/Ê/g,"ส");
		html = html.replace(/Ë/g,"ห");
		html = html.replace(/Ì/g,"ฬ");
		html = html.replace(/�/g,"อ");
		html = html.replace(/Î/g,"ฮ");
		html = html.replace(/æ/g,"ๆ");
		html = html.replace(/�/g,"ฯ");
		html = html.replace(/ç/g,"็");
		html = html.replace(/í/g,"�");
		html = html.replace(/Ú/g,"ฺ");
		html = html.replace(/�/g,"ะ");
		html = html.replace(/Ñ/g,"ั");
		html = html.replace(/Ò/g,"า");
		html = html.replace(/Ó/g,"ำ");
		html = html.replace(/å/g,"ๅ");
		html = html.replace(/Ô/g,"ิ");
		html = html.replace(/Õ/g,"ี");
		html = html.replace(/Ö/g,"ึ");
		html = html.replace(/×/g,"ื");
		html = html.replace(/Ø/g,"ุ");
		html = html.replace(/Ù/g,"ู");
		html = html.replace(/à/g,"เ");
		html = html.replace(/á/g,"�");
		html = html.replace(/â/g,"โ");
		html = html.replace(/ä/g,"ไ");
		html = html.replace(/ã/g,"ใ");
		html = html.replace(/è/g,"่");
		html = html.replace(/é/g,"้");
		html = html.replace(/ê/g,"๊");
		html = html.replace(/ë/g,"๋");
		html = html.replace(/ì/g,"์");
		html = html.replace(/ð/g,"�");
		html = html.replace(/ñ/g,"๑");
		html = html.replace(/ò/g,"๒");
		html = html.replace(/ó/g,"๓");
		html = html.replace(/ô/g,"๔");
		html = html.replace(/õ/g,"๕");
		html = html.replace(/ö/g,"่๖");
		html = html.replace(/÷/g,"๗");
		html = html.replace(/ø/g,"๘");
		html = html.replace(/ù/g,"๙");
		this.innerHTML = html;
	}
	
	function fixThaiToEnglish()
	{
		//Modify by ooooo - E-mail: stopeat@gmail.com
		//Original code by Rotem Liss and Liron Newman, http://eesh.net
		
		var html = this.value;
		html = html.replace(/�/g,"¡");
		html = html.replace(/ข/g,"¢");
		html = html.replace(/ฃ/g,"£");
		html = html.replace(/ค/g,"¤");
		html = html.replace(/ฅ/g,"¥");
		html = html.replace(/ฆ/g,"¦");
		html = html.replace(/ง/g,"§");
		html = html.replace(/จ/g,"¨");
		html = html.replace(/ฉ/g,"©");
		html = html.replace(/ช/g,"ª");
		html = html.replace(/ซ/g,"«");
		html = html.replace(/ฌ/g,"¬");
		html = html.replace(/�/g,"­");
		html = html.replace(/ฎ/g,"®");
		html = html.replace(/�/g,"¯");
		html = html.replace(/�/g,"°");
		html = html.replace(/ฑ/g,"±");
		html = html.replace(/ฒ/g,"²");
		html = html.replace(/ณ/g,"³");
		html = html.replace(/ด/g,"´");
		html = html.replace(/ต/g,"µ");
		html = html.replace(/ถ/g,"¶");
		html = html.replace(/ท/g,"·");
		html = html.replace(/ธ/g,"¸");
		html = html.replace(/น/g,"¹");
		html = html.replace(/บ/g,"º");
		html = html.replace(/ป/g,"»");
		html = html.replace(/ผ/g,"¼");
		html = html.replace(/�/g,"½");
		html = html.replace(/พ/g,"¾");
		html = html.replace(/ฟ/g,"¿");
		html = html.replace(/ภ/g,"À");
		html = html.replace(/ม/g,"�");
		html = html.replace(/ย/g,"Â");
		html = html.replace(/ร/g,"Ã");
		html = html.replace(/ฤ/g,"Ä");
		html = html.replace(/ล/g,"Å");
		html = html.replace(/ฦ/g,"Æ");
		html = html.replace(/ว/g,"Ç");
		html = html.replace(/ศ/g,"È");
		html = html.replace(/ษ/g,"É");
		html = html.replace(/ส/g,"Ê");
		html = html.replace(/ห/g,"Ë");
		html = html.replace(/ฬ/g,"Ì");
		html = html.replace(/อ/g,"�");
		html = html.replace(/ฮ/g,"Î");
		html = html.replace(/ๆ/g,"æ");
		html = html.replace(/ฯ/g,"�");
		html = html.replace(/็/g,"ç");
		html = html.replace(/�/g,"í");
		html = html.replace(/ฺ/g,"Ú");
		html = html.replace(/ะ/g,"�");
		html = html.replace(/ั/g,"Ñ");
		html = html.replace(/า/g,"Ò");
		html = html.replace(/ำ/g,"Ó");
		html = html.replace(/ๅ/g,"å");
		html = html.replace(/ิ/g,"Ô");
		html = html.replace(/ี/g,"Õ");
		html = html.replace(/ึ/g,"Ö");
		html = html.replace(/ื/g,"×");
		html = html.replace(/ุ/g,"Ø");
		html = html.replace(/ู/g,"Ù");
		html = html.replace(/เ/g,"à");
		html = html.replace(/�/g,"á");
		html = html.replace(/โ/g,"â");
		html = html.replace(/ไ/g,"ä");
		html = html.replace(/ใ/g,"ã");
		html = html.replace(/่/g,"è");
		html = html.replace(/้/g,"é");
		html = html.replace(/๊/g,"ê");
		html = html.replace(/๋/g,"ë");
		html = html.replace(/์/g,"ì");
		html = html.replace(/�/g,"ð");
		html = html.replace(/๑/g,"ñ");
		html = html.replace(/๒/g,"ò");
		html = html.replace(/๓/g,"ó");
		html = html.replace(/๔/g,"ô");
		html = html.replace(/๕/g,"õ");
		html = html.replace(/๖/g,"ö่");
		html = html.replace(/๗/g,"÷");
		html = html.replace(/๘/g,"ø");
		html = html.replace(/๙/g,"ù");
		this.value = html;
	}
	
	HTMLInputElement.prototype.fixThaiToEnglish = fixThaiToEnglish;
	HTMLTextAreaElement.prototype.fixThaiToEnglish = fixThaiToEnglish;
	
	function submitComposeForm(e) //Created by Rotem Liss
	{
		document.getElementById("alternateSubject").value = document.getElementById("subject").value;
		document.getElementById("alternateSubject").fixThaiToEnglish();
		
		document.getElementById("alternateBody").value = document.getElementById("body").value;
		document.getElementById("alternateBody").fixThaiToEnglish(); //Fix Body
	}
	
	if ((location.href.indexOf("compose") == -1) && (document.characterSet == "ISO-8859-1"))
	{
		if (document.characterSet == "ISO-8859-1")
		{
			if (document.getElementById("MsgTable"))
			{
				document.getElementById("MsgTable").fixEnglishToThai();
				document.body.childNodes[14].firstChild.firstChild.firstChild.firstChild.firstChild.
				 fixEnglishToThai();
			}
			else
			{
				document.body.fixEnglishToThai();
			}
		}
	}
	else
	{
		if (document.characterSet == "ISO-8859-1")
		{
			document.getElementById("HMTB").firstChild.childNodes[1].firstChild.firstChild.firstChild.
			 firstChild.childNodes[1].addEventListener("mousedown", submitComposeForm, true);
			
			var alternateSubject = document.getElementById("subject").cloneNode(true);
			alternateSubject.type = "hidden";
			alternateSubject.id = "alternateSubject";
			alternateSubject.name = "subject";
			document.forms["composeform"].appendChild(alternateSubject);
			document.getElementById("subject").name = "";
			
			//Find body
			var textareas = document.getElementsByTagName("textarea");
			var i;
			for (i = 1; (i <= textareas.length); i++)
			{
				if (textareas[i - 1].name == "body")
				{
					textareas[i - 1].id = "body";
					break;
				}
			}
			
			var alternateBody = document.getElementById("body").cloneNode(true);
			alternateBody.style.display = "none";
			alternateBody.id = "alternateBody";
			alternateBody.name = "body";
			document.forms["composeform"].appendChild(alternateBody);
			document.getElementById("body").name = "";
		
		}
	}
})();