@@ -2,6 +2,14 @@ window.addEventListener("message", receiveMessage, false);
22
33var _change = 0 ;
44
5+ function encode_utf8 ( s ) {
6+ return unescape ( encodeURIComponent ( s ) ) ;
7+ }
8+
9+ function decode_utf8 ( s ) {
10+ return decodeURIComponent ( escape ( s ) ) ;
11+ }
12+
513function receiveMessage ( event ) {
614 if ( event . data !== "!_{h:''}" ) {
715 var json = JSON . parse ( event . data ) ;
@@ -18,11 +26,12 @@ function receiveMessage(event){
1826 makeChat ( json . message , json . name , json . id , json . photo ) ;
1927 }
2028 else if ( json . type === "text" ) {
29+ console . log ( json . text ) ;
2130 try {
22- text . setText ( json . text ) ;
23- }
24- catch ( e ) {
25- }
31+ text . setText ( decode_utf8 ( json . text ) ) ;
32+ }
33+ catch ( e ) {
34+ }
2635 }
2736 }
2837}
@@ -39,9 +48,10 @@ function sendData(data){
3948}
4049
4150function setValue ( value ) {
51+ console . log ( value ) ;
4252 sendData ( {
4353 type : "text" ,
44- value : value ,
54+ value : encode_utf8 ( value ) ,
4555 currentfile : current_file
4656 } ) ;
4757}
@@ -67,7 +77,7 @@ function removeUser(the_id){
6777}
6878
6979function setText ( value ) {
70- text . setText ( value ) ;
80+ text . setText ( decode_utf8 ( value ) ) ;
7181}
7282
7383function insertChat ( the_message , the_name , is_you , the_photo , is_new ) {
@@ -86,7 +96,7 @@ function insert_text(point, text){
8696 sendData ( {
8797 type : "insert_text" ,
8898 point : point ,
89- text : text ,
99+ text : encode_utf8 ( text ) ,
90100 currentfile : current_file
91101 } ) ;
92102}
0 commit comments