Skip to content

Commit 9bcb6c6

Browse files
committed
wip
1 parent 20f61d6 commit 9bcb6c6

File tree

7 files changed

+281
-83
lines changed

7 files changed

+281
-83
lines changed

scripts/content-scripts/scripts/ufs_global_webpage_context.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,16 @@ const UsefulScriptGlobalPageContext = {
183183

184184
let text = await res.text();
185185
return {
186+
uid: uid,
186187
name: UsefulScriptsUtils.decodeEscapedUnicodeString(
187188
/"name":"(.*?)"/.exec(text)?.[1]
188189
),
189-
profiePicLarge: UsefulScriptsUtils.decodeEscapedUnicodeString(
190-
/"profilePicLarge":{"uri":"(.*?)"/.exec(text)?.[1]
190+
avatar: UsefulScriptsUtils.decodeEscapedUnicodeString(
191+
/"profilePicLarge":{"uri":"(.*?)"/.exec(text)?.[1] ||
192+
/"profilePicMedium":{"uri":"(.*?)"/.exec(text)?.[1] ||
193+
/"profilePicSmall":{"uri":"(.*?)"/.exec(text)?.[1] ||
194+
/"profilePic160":{"uri":"(.*?)"/.exec(text)?.[1]
191195
),
192-
// profiePicMedium: /"profilePicMedium":{"uri":"(.*?)"/.exec(text)?.[1],
193-
// profiePicSmall: /"profilePicSmall":{"uri":"(.*?)"/.exec(text)?.[1],
194-
// profilePic160: /"profilePic160":{"uri":"(.*?)"/.exec(text)?.[1],
195196
gender: /"gender":"(.*?)"/.exec(text)?.[1],
196197
alternateName: /"alternate_name":"(.*?)"/.exec(text)?.[1],
197198
};
@@ -203,7 +204,13 @@ const UsefulScriptGlobalPageContext = {
203204
"/?fields=name,picture&access_token=" +
204205
access_token;
205206
const e = await fetch(n);
206-
return await e.json();
207+
let json = await e.json();
208+
209+
return {
210+
uid: uid,
211+
name: json?.name,
212+
avatar: json?.picture?.data?.url,
213+
};
207214
},
208215
decodeArrId(arrId) {
209216
return arrId[0] * 4294967296 + arrId[1];

scripts/fb_messengerCount.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export default {
1010
en: "Counts the number of messages sent from your Facebook Messenger account.",
1111
vi: "Đếm tin nhắn từ tài khoản Facebook Messenger của bạn.",
1212
},
13-
infoLink: "",
1413
whiteList: ["https://*.facebook.com/*", "https://*.messenger.com/*"],
1514

1615
onClickExtension: async () => {

scripts/fb_messengerHistory.css

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
body {
2+
max-width: 700px;
3+
margin: auto;
4+
padding: 10px;
5+
}
6+
7+
label,
8+
button,
9+
p {
10+
font-size: 1.2em;
11+
}
12+
13+
button {
14+
background-color: #04AA6D;
15+
color: white;
16+
padding: 12px 20px;
17+
border: none;
18+
border-radius: 4px;
19+
cursor: pointer;
20+
}
21+
22+
button:hover {
23+
background-color: #01cf83;
24+
}
25+
26+
h1 {
27+
text-align: center;
28+
}
29+
30+
table {
31+
width: 100%;
32+
}
33+
34+
input[type=text],
35+
select,
36+
textarea {
37+
width: 80%;
38+
padding: 12px;
39+
border: 1px solid #ccc;
40+
border-radius: 4px;
41+
}
42+
43+
.overlay {
44+
position: fixed;
45+
top: 0;
46+
left: 0;
47+
right: 0;
48+
bottom: 0;
49+
background-color: rgba(0, 0, 0, 0.5);
50+
display: none;
51+
align-items: center;
52+
justify-content: center;
53+
}
54+
55+
#loading-text {
56+
color: white;
57+
font-weight: bold;
58+
font-size: 1.2em;
59+
margin-left: 10px;
60+
}
61+
62+
.loader {
63+
border: 10px solid #f3f3f3;
64+
border-top: 10px solid #3498db;
65+
border-radius: 50%;
66+
width: 30px;
67+
height: 30px;
68+
animation: spin 1s linear infinite;
69+
}
70+
71+
@keyframes spin {
72+
0% {
73+
transform: rotate(0deg);
74+
}
75+
76+
100% {
77+
transform: rotate(360deg);
78+
}
79+
}

scripts/fb_messengerHistory.html

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8+
<title>Useful script - Facebook messenger history</title>
9+
10+
<script src="./content-scripts/scripts/ufs_global_webpage_context.js"></script>
11+
<link rel="stylesheet" href="./fb_messengerHistory.css">
12+
</head>
13+
14+
<body>
15+
<h1>Useful script</h1>
16+
<h1>Facebook messenger - Xem tin nhắn đầu tiên</h1>
17+
18+
<table>
19+
<tr>
20+
<td><label>Link profile bạn bè:</label></td>
21+
<td><input id="inp-friend-url" type="text" placeholder="Nhập link profile bạn bè..."></td>
22+
<td rowspan="2"><button id="btn-scan">Bắt đầu Scan</button></td>
23+
</tr>
24+
<tr>
25+
<td><label>Access token của bạn:</label></td>
26+
<td><input id="inp-access-token" type="text" placeholder="Nhập access token..."></td>
27+
</tr>
28+
</table>
29+
30+
<div class="overlay">
31+
<div class="loader"></div>
32+
<p id="loading-text"></p>
33+
</div>
34+
35+
<script src="./fb_messengerHistory_main.js"></script>
36+
</body>
37+
38+
</html>

scripts/fb_messengerHistory.js

Lines changed: 2 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -8,79 +8,8 @@ export default {
88
en: "View first message in facebook messenger",
99
vi: "Xem tin nhắn đầu tiên với bạn bè trong facebook messenger",
1010
},
11-
whiteList: ["https://*.facebook.com/*", "https://*.messenger.com/*"],
1211

13-
onClick: async () => {
14-
let friend_uid = prompt("Nhâp uid của bạn bè:", "");
15-
let token = prompt("Nhập access token: ");
16-
17-
const Global = {
18-
endpoint: "https://www.facebook.com/api/graphqlbatch/",
19-
mid: null,
20-
right: Date.now(),
21-
left: new Date("1/1/2004").getTime(),
22-
csrf_token: await UsefulScriptGlobalPageContext.Facebook.getFbdtsg(),
23-
access_token: token,
24-
};
25-
26-
function startScan() {}
27-
28-
function search() {
29-
return new Promise(function (t) {
30-
Math.abs(n.l - n.r) <= 1e3
31-
? ((n.loading = !1),
32-
null === n.result ? (n.error = !0) : ((n.error = !1), t(n.result)))
33-
: ((n.mid = 1e3 * Math.round((n.l + n.r) / 2 / 1e3)),
34-
n.isExist(n.mid, e).then(function (r) {
35-
r.length === e
36-
? ((n.r = n.mid - 1), (n.result = r))
37-
: (n.l = n.mid + 1),
38-
n.search(e).then(t);
39-
}));
40-
});
41-
}
42-
43-
function getMessageAfter() {}
44-
45-
function makeQuery(cursor, limit) {
46-
return {
47-
o0: {
48-
doc_id: "1526314457427586",
49-
query_params: {
50-
id: this.friend_info.id,
51-
message_limit: limit,
52-
load_messages: 1,
53-
load_read_receipts: !0,
54-
before: cursor,
55-
},
56-
},
57-
};
58-
}
59-
function isExist(cursor, limit) {
60-
return new Promise(function (resolve, reject) {
61-
fetch(Global.endpoint, {
62-
headers: { "Content-Type": "application/x-www-form-urlencoded" },
63-
method: "POST",
64-
body:
65-
"fb_dtsg=" +
66-
t.csrf_token +
67-
"&queries=" +
68-
JSON.stringify(makeQuery(cursor, limit)),
69-
credentials: "include",
70-
})
71-
.then(function (e) {
72-
return e.text();
73-
})
74-
.then(function (e) {
75-
try {
76-
var n = JSON.parse(e.split("\n")[0]);
77-
if (n.o0.data.message_thread)
78-
resolve(n.o0.data.message_thread.messages.nodes);
79-
} catch (i) {
80-
console.error(i.message);
81-
}
82-
});
83-
});
84-
}
12+
onClickExtension: async () => {
13+
window.open(chrome.runtime.getURL("scripts/fb_messengerHistory.html"));
8514
},
8615
};

scripts/fb_messengerHistory_main.js

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
window.onload = async () => {
2+
const Global = {
3+
endpoint: "https://www.facebook.com/api/graphqlbatch/",
4+
mid: null,
5+
right: Date.now(),
6+
left: new Date("1/1/2004").getTime(),
7+
fb_dtsg: await UsefulScriptGlobalPageContext.Facebook.getFbdtsg(),
8+
};
9+
10+
console.log(Global);
11+
12+
// query elements
13+
let friend_url_inp = document.querySelector("#inp-friend-url");
14+
let access_token_inp = document.querySelector("#inp-access-token");
15+
let btnScan = document.querySelector("#btn-scan");
16+
let loadingOverlay = document.querySelector(".overlay");
17+
let loadingText = document.querySelector("#loading-text");
18+
19+
// init
20+
access_token_inp.value = localStorage.ufs_fb_messenger_history || "";
21+
access_token_inp.addEventListener("input", function (e) {
22+
localStorage.ufs_fb_messenger_history = access_token_inp.value;
23+
});
24+
btnScan.onclick = scan;
25+
26+
// functions
27+
async function scan() {
28+
try {
29+
let friend_url = friend_url_inp.value;
30+
let access_token = access_token_inp.value;
31+
if (!friend_url) throw new Error("Vui lòng nhập link profile của bạn bè");
32+
if (!access_token) throw new Error("Vui lòng nhập access token của bạn");
33+
34+
showLoading("Đang lấy thông tin bạn bè...");
35+
let friendUid =
36+
await UsefulScriptGlobalPageContext.Facebook.getUidFromUrl(friend_url);
37+
let friendInfo = await UsefulScriptGlobalPageContext.Facebook.getUserInfo(
38+
friendUid,
39+
access_token
40+
);
41+
console.log(friendInfo);
42+
} catch (e) {
43+
alert("ERROR: " + e);
44+
} finally {
45+
showLoading(false);
46+
}
47+
}
48+
49+
function showLoading(text) {
50+
loadingOverlay.style.display = text ? "flex" : "none";
51+
if (typeof text === "string") loadingText.innerText = text;
52+
}
53+
54+
return;
55+
56+
function startScan() {}
57+
58+
function search() {
59+
return new Promise(function (t) {
60+
Math.abs(n.l - n.r) <= 1e3
61+
? ((n.loading = !1),
62+
null === n.result ? (n.error = !0) : ((n.error = !1), t(n.result)))
63+
: ((n.mid = 1e3 * Math.round((n.l + n.r) / 2 / 1e3)),
64+
n.isExist(n.mid, e).then(function (r) {
65+
r.length === e
66+
? ((n.r = n.mid - 1), (n.result = r))
67+
: (n.l = n.mid + 1),
68+
n.search(e).then(t);
69+
}));
70+
});
71+
}
72+
73+
function getMessageAfter(msgId, limit) {
74+
return new Promise(function (r, i) {
75+
fetch("https://www.facebook.com/ajax/mercury/search_context.php", {
76+
headers: {
77+
"Content-Type": "application/x-www-form-urlencoded",
78+
},
79+
method: "POST",
80+
body:
81+
"message_id=" +
82+
msgId +
83+
"&limit=" +
84+
limit +
85+
"&direction=down&other_user_fbid=" +
86+
t.friend_info.id +
87+
"&__a=1&fb_dtsg=" +
88+
t.csrf_token,
89+
credentials: "include",
90+
})
91+
.then(function (e) {
92+
return e.text();
93+
})
94+
.then(function (e) {
95+
var n = JSON.parse(e.substr(9)),
96+
t = n.payload.graphql_payload;
97+
if (t) r(t);
98+
else {
99+
var o = new Error("There is no results.");
100+
i(o);
101+
}
102+
});
103+
});
104+
}
105+
106+
function makeQuery(cursor, limit) {
107+
return {
108+
o0: {
109+
doc_id: "1526314457427586",
110+
query_params: {
111+
id: this.friend_info.id,
112+
message_limit: limit,
113+
load_messages: 1,
114+
load_read_receipts: !0,
115+
before: cursor,
116+
},
117+
},
118+
};
119+
}
120+
function isExist(cursor, limit) {
121+
return new Promise(function (resolve, reject) {
122+
fetch(Global.endpoint, {
123+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
124+
method: "POST",
125+
body:
126+
"fb_dtsg=" +
127+
t.csrf_token +
128+
"&queries=" +
129+
JSON.stringify(makeQuery(cursor, limit)),
130+
credentials: "include",
131+
})
132+
.then(function (e) {
133+
return e.text();
134+
})
135+
.then(function (e) {
136+
try {
137+
var n = JSON.parse(e.split("\n")[0]);
138+
if (n.o0.data.message_thread)
139+
resolve(n.o0.data.message_thread.messages.nodes);
140+
} catch (i) {
141+
console.error(i.message);
142+
}
143+
});
144+
});
145+
}
146+
};

0 commit comments

Comments
 (0)