@@ -11,7 +11,20 @@ export default {
1111 whiteList : [ "https://*.facebook.com/*" , "https://*.messenger.com/*" ] ,
1212
1313 onDocumentStart : ( ) => {
14- window . ufs_whoIsTyping_Cached = { } ;
14+ const key = "ufs_fb_whoIsTyping" ;
15+ try {
16+ window . ufs_fb_whoIsTyping = JSON . parse ( localStorage . getItem ( key ) || "[]" ) ;
17+ } catch ( e ) {
18+ console . log ( "ERROR" , e ) ;
19+ window . ufs_fb_whoIsTyping = [ ] ;
20+ }
21+
22+ window . onbeforeunload = ( ) => {
23+ if ( window . ufs_fb_whoIsTyping )
24+ localStorage . setItem ( key , JSON . stringify ( window . ufs_fb_whoIsTyping ) ) ;
25+ } ;
26+
27+ window . ufs_whoIsTyping_users_cache = { } ;
1528
1629 let textDecoder = new TextDecoder ( "utf-8" ) ;
1730 const WebSocketOrig = window . WebSocket ;
@@ -30,15 +43,24 @@ export default {
3043 try {
3144 let isStartTyping = utf8_str . includes ( ",true" ) ;
3245 let isStopTyping = utf8_str . includes ( ",false" ) ;
33- let uid = / \\ \" ( \d + ) \\ \" / g . exec ( utf8_str ) [ 1 ] ;
46+ let uid = utf8_str . match ( / (? ! \" ) ( \d { 3 , } ) / g ) ?. [ 1 ] ;
3447
35- if ( ! ( uid in window . ufs_whoIsTyping_Cached ) ) {
48+ if ( ! ( uid in window . ufs_whoIsTyping_users_cache ) ) {
3649 let userData = await UfsGlobal . Facebook . getUserInfoFromUid ( uid ) ;
37- window . ufs_whoIsTyping_Cached [ uid ] = userData ;
50+ window . ufs_whoIsTyping_users_cache [ uid ] = userData ;
3851 }
3952
40- let { name, avatar } = window . ufs_whoIsTyping_Cached [ uid ] ;
53+ let { name, avatar } = window . ufs_whoIsTyping_users_cache [ uid ] ;
4154 notifyTypingEvent ( uid , name , avatar , isStartTyping ) ;
55+ window . ufs_fb_whoIsTyping . push ( {
56+ uid,
57+ name,
58+ avatar,
59+ type : isStartTyping ? "start" : "stop" ,
60+ time : new Date ( ) . getTime ( ) ,
61+ } ) ;
62+ if ( window . ufs_fb_whoIsTyping . length > 1000 )
63+ window . ufs_fb_whoIsTyping . shift ( ) ;
4264 } catch ( e ) {
4365 console . log ( "ERROR: " , e ) ;
4466 }
0 commit comments