@@ -16,39 +16,207 @@ export default {
1616 onDocumentStart : ( ) => {
1717 const WebSocketOrig = window . WebSocket ;
1818 window . WebSocket = function fakeConstructor ( dt , config ) {
19+ // hàm hỗ trợ
20+ const isMsgIdStr = ( str ) => str ?. startsWith ( "mid.$" ) ;
21+ const isLink = ( str ) => str ?. startsWith ( "https://" ) ;
22+
23+ // Hàm decode data websocket về tiếng việt, loại bỏ những thằng \\
24+ const parse = ( str ) => {
25+ let ret = str ;
26+ let limit = 10 ;
27+ while ( -- limit > 0 ) {
28+ try {
29+ if ( ret [ 0 ] === '"' ) ret = JSON . parse ( ret ) ;
30+ else ret = JSON . parse ( `"${ ret } "` ) ;
31+ } catch ( e ) {
32+ break ;
33+ }
34+ }
35+ return ret ;
36+ } ;
37+
38+ const ChatType = {
39+ text : "text" ,
40+ image : "image" ,
41+ video : "video" ,
42+ GIF : "gif" ,
43+ audio : "audio" ,
44+ attachment : "attachment" ,
45+ sticker : "sticker" ,
46+ add_reaction : "add_reaction" ,
47+ remove_reaction : "remove_reaction" ,
48+ share_location : "share_location" ,
49+ pending : "pending" ,
50+ user_data : "user_data" ,
51+ delete_msg : "delete_msg" ,
52+ } ;
53+
54+ function findAllChatData ( all_strings ) {
55+ let chats = [ ] ;
56+ for ( let i = 0 ; i < all_strings . length ; i ++ ) {
57+ const str_i = all_strings [ i ] ;
58+
59+ // Tin nhắn chữ
60+ if ( str_i === "insertMessage" && isMsgIdStr ( all_strings [ i + 2 ] ) ) {
61+ const content = all_strings [ i + 1 ] ;
62+ if ( content ) {
63+ chats . push ( {
64+ type : ChatType . text ,
65+ content : content ,
66+ id : all_strings [ i + 2 ] ,
67+ } ) ;
68+ }
69+ }
70+
71+ // Tin nhắn đính kèm: image / gif / video / âm thanh / file
72+ if ( str_i === "insertBlobAttachment" && isLink ( all_strings [ i + 2 ] ) ) {
73+ const a1 = all_strings [ i + 1 ] ;
74+ const isImg = a1 ?. startsWith ( "image-" ) ;
75+ const isGif = a1 ?. startsWith ( "gif-" ) ;
76+ const isVideo = a1 ?. startsWith ( "video-" ) ;
77+ const isAudio = a1 ?. startsWith ( "audioclip-" ) ;
78+ const type = isImg
79+ ? ChatType . image
80+ : isGif
81+ ? ChatType . GIF
82+ : isVideo
83+ ? ChatType . video
84+ : isAudio
85+ ? ChatType . audio
86+ : ChatType . attachment ;
87+
88+ for ( let j = i ; j < all_strings . length - 1 ; j ++ ) {
89+ if ( isMsgIdStr ( all_strings [ j ] ) ) {
90+ chats . push ( {
91+ type : type ,
92+ content : all_strings [ i + 2 ] ,
93+ id : all_strings [ j ] ,
94+ } ) ;
95+ break ;
96+ }
97+ }
98+ }
99+
100+ // Tin nhắn nhãn dán
101+ if (
102+ str_i === "insertMessage" &&
103+ isMsgIdStr ( all_strings [ i + 1 ] ) &&
104+ isLink ( all_strings [ i + 6 ] )
105+ ) {
106+ chats . push ( {
107+ type : ChatType . sticker ,
108+ content : all_strings [ i + 6 ] ,
109+ id : all_strings [ i + 1 ] ,
110+ } ) ;
111+ }
112+
113+ // Thả react
114+ if ( str_i === "upsertReaction" && isMsgIdStr ( all_strings [ i + 1 ] ) ) {
115+ chats . push ( {
116+ type : ChatType . add_reaction ,
117+ content : all_strings [ i + 2 ] ,
118+ id : all_strings [ i + 1 ] ,
119+ } ) ;
120+ }
121+
122+ // Gỡ react
123+ if ( str_i === "deleteReaction" && isMsgIdStr ( all_strings [ i + 1 ] ) ) {
124+ const id = all_strings [ i + 1 ] ;
125+ const content =
126+ rvdfm_all_msgs . find ( ( c ) => c . id === id ) ?. content || "" ;
127+
128+ chats . push ( {
129+ type : ChatType . remove_reaction ,
130+ content : content ,
131+ id : id ,
132+ } ) ;
133+ }
134+
135+ // Tin nhắn chia sẻ vị trí / vị trí trực tiếp
136+ if (
137+ str_i === "xma_live_location_sharing" &&
138+ isMsgIdStr ( all_strings [ i - 2 ] ) &&
139+ isLink ( all_strings [ i + 1 ] )
140+ ) {
141+ const link = all_strings [ i + 1 ] ;
142+
143+ chats . push ( {
144+ type : ChatType . share_location ,
145+ content : link ,
146+ id : all_strings [ i - 2 ] ,
147+ } ) ;
148+ }
149+
150+ // Thông tin user
151+ // if (str_i === "533" && isLink(all_strings[i + 1])) {
152+ // const avatar = all_strings[i + 1];
153+ // const user_name = all_strings[i + 2];
154+
155+ // chats.push({
156+ // type: ChatType.user_data,
157+ // avatar: avatar,
158+ // name: user_name,
159+ // });
160+ // }
161+
162+ // Tin nhắn đang chờ
163+ // if (str_i === "130" && all_strings[i + 3] === "pending") {
164+ // chats.push({
165+ // type: ChatType.pending,
166+ // content: all_strings[i + 1],
167+ // avatar: all_strings[i + 2],
168+ // });
169+ // }
170+
171+ // Thu hồi tin nhắn
172+ if (
173+ str_i === "deleteThenInsertMessage" &&
174+ isMsgIdStr ( all_strings [ i + 2 ] )
175+ ) {
176+ const id = all_strings [ i + 2 ] ;
177+ const msgs =
178+ rvdfm_all_msgs . filter (
179+ ( c ) => c . id === id && c . type !== "Thu hồi"
180+ ) || [ ] ;
181+
182+ chats . push ( {
183+ type : ChatType . delete_msg ,
184+ msgs : msgs ,
185+ id : id ,
186+ } ) ;
187+ }
188+ }
189+
190+ // Chèn thời gian hiện tại vào
191+ chats = chats . map ( ( _ ) => ( { ..._ , time : Date . now ( ) } ) ) ;
192+
193+ console . log ( "Thông tin lọc được:" , chats ) ;
194+ }
195+
196+ // ====== Start hacking ======
19197 const websocket_instant = new WebSocketOrig ( dt , config ) ;
20198 websocket_instant . addEventListener ( "message" , async function ( achunk ) {
21199 const utf8_str = new TextDecoder ( "utf-8" ) . decode ( achunk . data ) ;
22- // Do something here
23200
24- if ( utf8_str . includes ( "updateTypingIndicator" ) ) {
25- // console.log(utf8_str);
201+ if ( utf8_str [ 0 ] === "1" || utf8_str [ 0 ] === "2" || utf8_str [ 0 ] === "3" ) {
202+ const have_msg_id = / (? = m i d \. \$ ) ( .* ?) (? = \\ " ) / . exec ( utf8_str ) ;
203+ if ( have_msg_id ) {
204+ // Lấy ra tất cả các thông tin dùng được trong dữ liệu (những chuỗi nằm giữa 2 dấu nháy kép "")
205+ const all_strings_regex = / ( \\ \" ) ( .* ?) ( \\ \" ) (? = [ , ) ] ) / g;
206+ let all_strings = utf8_str . match ( all_strings_regex ) || [ ] ;
207+ all_strings = all_strings . map ( ( str ) => parse ( str ) ) ;
208+
209+ if ( all_strings . length ) {
210+ findAllChatData ( all_strings ) ;
211+ }
212+ }
26213 }
27214 } ) ;
215+
28216 return websocket_instant ;
29217 } ;
30218 window . WebSocket . prototype = WebSocketOrig . prototype ;
31219 window . WebSocket . prototype . constructor = window . WebSocket ;
32- // window.addEventListener(
33- // "message",
34- // function (t) {
35- // t.source == window && console.log(t);
36- // },
37- // !1
38- // );
39- // let emptyFunc = void 0;
40- // Object.defineProperty(window, "__d", {
41- // get: () => emptyFunc,
42- // set: (i) => {
43- // const c = new Proxy(i, {
44- // apply: function (target, thisArg, arg) {
45- // console.log(thisArg);
46- // return target(...arg);
47- // },
48- // });
49- // emptyFunc = c;
50- // },
51- // });
52220 } ,
53221 onDocumentIdle : ( ) => {
54222 // tất cả loại tin nhắn đều được bao bọc bởi:
@@ -64,8 +232,8 @@ export default {
64232 ) ;
65233
66234 requireLazy (
67- [ "MWV2ChatUnsentMessage.bs" , "MWPBaseMessage.bs" , "MqttProtocolClient" ] ,
68- ( MWV2ChatUnsentMessage , MWPBaseMessage , MqttProtocolClient ) => {
235+ [ "MWV2ChatUnsentMessage.bs" , "MWPBaseMessage.bs" ] ,
236+ ( MWV2ChatUnsentMessage , MWPBaseMessage ) => {
69237 // Override unsent message component
70238 const MWV2ChatUnsentMessageOrig = MWV2ChatUnsentMessage . make ;
71239 MWV2ChatUnsentMessage . make = function ( a ) {
@@ -97,50 +265,7 @@ export default {
97265 }
98266 return MWV2ChatUnsentMessageOrig . apply ( this , arguments ) ;
99267 } ;
100-
101- // Listen for chat event
102- const MqttProtocolClientOrig = MqttProtocolClient . prototype . publish ;
103- MqttProtocolClient . prototype . publish = function ( ) {
104- let b = arguments [ 1 ] ;
105- console . log ( b ) ;
106- // if (b && b.includes('\\\\\\"text\\\\\\":')) {
107- // (function () {
108- // b = JSON.parse(b);
109- // if (!b || !b.payload) return;
110- // let payload = JSON.parse(b.payload);
111- // if (!payload || !payload.tasks) return;
112-
113- // payload.tasks = payload.tasks.map((task) => {
114- // let payload = JSON.parse(task.payload);
115- // if (!payload || !payload.text) return task;
116- // if (payload.text.length > 1 && payload.text[0] === ">") {
117- // payload.text = encode(payload.text.substr(1));
118- // }
119- // task.payload = JSON.stringify(payload);
120- // return task;
121- // });
122-
123- // b.payload = JSON.stringify(payload);
124- // b = JSON.stringify(b);
125- // })();
126- // arguments[1] = b;
127- // }
128- return MqttProtocolClientOrig . apply ( this , arguments ) ;
129- } ;
130268 }
131269 ) ;
132-
133- // Test who is typing
134- // MWChatTypingIndicator.bs
135- // MWPTypingIndicators.bs
136- requireLazy ( [ "LSUpdateTypingIndicator" ] , ( LSUpdateTypingIndicator ) => {
137- // alert("abc");
138- const LSUpdateTypingIndicatorOrig = LSUpdateTypingIndicator ;
139-
140- LSUpdateTypingIndicator = function ( ) {
141- console . log ( arguments ) ;
142- return LSUpdateTypingIndicatorOrig . apply ( this , arguments ) ;
143- } ;
144- } ) ;
145270 } ,
146271} ;
0 commit comments