Skip to content

Commit 6b708b6

Browse files
committed
WIP
1 parent 910c0f2 commit 6b708b6

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

empty_script.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ export default {
1111
},
1212
infoLink: "",
1313

14+
changeLogs: [
15+
{
16+
version: "",
17+
date: "",
18+
description: {
19+
en: "",
20+
vi: "",
21+
},
22+
},
23+
],
1424
blackList: [],
1525
whiteList: [],
1626

scripts/fb_whoIsTyping.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)