DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Change Gmail Encoding To Display Thai.
Some emails send from yahoo and hotmail will display thai incorrectly. This bookmarklet re-encode it by shifting the unicode numbers. Can be applied to some language whose encoding is in the same "shifting" order.
javascript:(function(){ map=[];for(i=161;i<251;i++)map[i]=String.fromCharCode(i+3424); function thai(s){s2='';for(var i=0;i<s.length;i++){n=s.charCodeAt(i);if(n>160&&n<251) s2+=map[n];else s2+=s.charAt(i)}return s2} function rc_thai(el){if(el.nodeType== 3){el.data=thai(el.data);return} if(el.tagName == 'SCRIPT') return; for (var i=0; i<el.childNodes.length; i++) rc_thai(el.childNodes[i])} for(i=0;i<4;i++){if(fi=window.frames[0].frames[i].document.getElementById('fi')) break} rc_thai(fi); })();
The one-liner version above maybe difficult to read. Here's a reorganized one
javascript:(function(){
map=[];
/* create conversion table */
for(i=161;i<251;i++) {
map[i]=String.fromCharCode(i+3424);
}
function thai(s){
s2='';
for(var i=0;i<s.length;i++){
n=s.charCodeAt(i);
if(n>160&&n<251)
s2+=map[n];
else
s2+=s.charAt(i)
}
return s2
}
/* recursively convert encoding of sub-element */
function rc_thai(el){
if(el.nodeType== 3){
el.data=thai(el.data);
return
}
if(el.tagName == 'SCRIPT')
return;
for (var i=0; i<el.childNodes.length; i++)
rc_thai(el.childNodes[i])
}
/* finding the content element in sub-sub-frame */
for(i=0;i<4;i++){
if(fi=window.frames[0].frames[i].document.getElementById('fi'))
break
}
/* change that element (and all its descendants */
rc_thai(fi);
})();





