Skip to content

Commit 76e4ccd

Browse files
committed
wip
1 parent f2c36c1 commit 76e4ccd

File tree

7 files changed

+151
-86
lines changed

7 files changed

+151
-86
lines changed

scripts/content-scripts/document_end.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(async () => {
22
let key = "activeScripts";
3-
let ids = (await chrome.storage.sync.get([key]))?.[key];
3+
let ids = (await chrome.storage.sync.get([key]))?.[key] || "";
44
window.dispatchEvent(
55
new CustomEvent("ufs-run-page-scripts", {
66
detail: {

scripts/content-scripts/document_idle.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(async () => {
22
let key = "activeScripts";
3-
let ids = (await chrome.storage.sync.get([key]))?.[key];
3+
let ids = (await chrome.storage.sync.get([key]))?.[key] || "";
44
window.dispatchEvent(
55
new CustomEvent("ufs-run-page-scripts", {
66
detail: {

scripts/content-scripts/document_start.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@
44

55
(async () => {
66
// https://stackoverflow.com/a/8578840/11898496
7-
function injectScript(src) {
7+
function injectScript(
8+
src,
9+
onload,
10+
type = "text/javascript",
11+
async = false,
12+
defer = false
13+
) {
814
let s = document.createElement("script");
9-
s.type = "text/javascript";
10-
s.async = false;
11-
s.defer = false;
15+
s.type = type;
16+
s.async = async;
17+
s.defer = defer;
1218
s.addEventListener("load", () => {
1319
console.log("Useful-scripts injected " + src);
20+
onload?.();
1421
s.remove();
1522
});
1623
s.src = src;
@@ -22,25 +29,25 @@
2229
// (document.head || document.documentElement).prepend(s);
2330
}
2431

32+
injectScript(
33+
chrome.runtime.getURL(
34+
"/scripts/content-scripts/scripts/ufs_global_webpage_context.js"
35+
)
36+
);
37+
2538
let key = "activeScripts";
26-
let ids = (await chrome.storage.sync.get([key]))?.[key];
39+
let ids = (await chrome.storage.sync.get([key]))?.[key] || "";
2740
let search = new URLSearchParams({
2841
ids: ids,
29-
path: chrome.runtime.getURL("/scripts/"),
3042
event: "onDocumentStart",
43+
path: chrome.runtime.getURL("/scripts/"),
3144
}).toString();
3245

3346
injectScript(
3447
chrome.runtime.getURL("/scripts/content-scripts/run_scripts.js") +
3548
"?" +
3649
search
3750
);
38-
39-
injectScript(
40-
chrome.runtime.getURL(
41-
"/scripts/content-scripts/scripts/ufs_global_webpage_context.js"
42-
)
43-
);
4451
})();
4552

4653
(async () => {

scripts/content-scripts/run_scripts.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,39 @@
77
// Kể cả việc nó đã được viết ở file khác (utils, helper, ...)
88
// Quá trình maintain sẽ khó hơn 1 chút, nhưng script sẽ chạy chính xác hơn
99

10-
console.log(window.__d);
11-
1210
(() => {
13-
const params = new URLSearchParams(
14-
document.currentScript.src.split("?")?.[1]
15-
);
16-
17-
let path = params.get("path");
11+
let search = new URLSearchParams(getCurrentScriptSrc().split("?")?.[1]);
12+
let path = search.get("path");
1813

1914
// run script on receive event
2015
window.addEventListener("ufs-run-page-scripts", ({ detail }) => {
2116
const { event, ids } = detail;
2217
runScripts(ids, event, path);
2318
});
2419

25-
// auto run onDocumentStart
20+
// auto run initial event defined in URL search params
2621
(() => {
27-
let ids = params.get("ids");
28-
let event = params.get("event");
29-
if (ids) {
22+
let ids = search.get("ids");
23+
let event = search.get("event");
24+
if (ids && event) {
3025
let scriptIds = ids.split(",");
3126
runScripts(scriptIds, event, path);
3227
}
3328
})();
3429
})();
3530

31+
function getCurrentScriptSrc() {
32+
try {
33+
// cannot get currentScript if script type is module: https://stackoverflow.com/a/45845801/11898496
34+
// return import.meta.url;
35+
throw false;
36+
} catch (e) {
37+
return document.currentScript.src;
38+
}
39+
}
40+
3641
function runScripts(scriptIds, event, path) {
3742
for (let id of scriptIds) {
38-
// import and run script with event name
3943
let scriptPath = `${path}/${id}.js`;
4044
import(scriptPath).then(({ default: script }) => {
4145
try {

scripts/fb_downloadWatchingVideo.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ export default {
99
vi: "Tải video fb đang xem",
1010
},
1111
description: {
12-
en: "Download facebook video that you are watching (watch/story/comment)",
13-
vi: "Tải video facebook bạn đang xem (watch/story/comment)",
12+
en: "Download any facebook video that you are watching (watch/story/comment/reel/chat)",
13+
vi: "Tải bất kỳ video facebook nào mà bạn đang xem (watch/story/comment/reel/chat/bình luận/tin nhắn)",
1414
},
1515
whiteList: ["https://www.facebook.com/*"],
1616

scripts/fb_invisible_message.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ export default {
55
vi: "Tin nhắn tàng hình facebook",
66
},
77
description: {
8-
en: "Add character > before message to send invisible message",
9-
vi: "Thêm ký tự > trước tin nhắn để tạo tin nhắn tàng hình",
8+
en: "Add the > character before writing a message to send hidden messages.\n\nYour friends needs to install this extension and enable it to view hidden messages.",
9+
vi: "Thêm ký tự > trước tin nhắn để tạo tin nhắn tàng hình.\n\nChỉ xem được tin nhắn tàng hình khi cài extension và bật chức năng này.",
1010
},
1111
whiteList: ["https://*.facebook.com/*", "https://*.messenger.com/*"],
1212

@@ -130,7 +130,6 @@ export default {
130130
};
131131

132132
const checkEncode = (s) => {
133-
//console.log(s);
134133
if (s?.[0] != PADDING) return false;
135134
s = s.substr(1);
136135
for (let c of s) if (CHARS_MAP[c] === undefined) return false;
@@ -143,8 +142,6 @@ export default {
143142
const MWV2ChatTextMakeOrig = MWV2ChatText.make;
144143
MWV2ChatText.make = function (a) {
145144
let text = a?.message?.text;
146-
console.log(a);
147-
if (a.message.text.includes("thu hồi")) console.log("here");
148145
if (checkEncode(text))
149146
a.message.text = `[Encrypted]: ${decode(text)}`;
150147
return MWV2ChatTextMakeOrig.apply(this, arguments);
@@ -163,7 +160,6 @@ export default {
163160

164161
payload.tasks = payload.tasks.map((task) => {
165162
let payload = JSON.parse(task.payload);
166-
console.log(payload);
167163
if (!payload || !payload.text) return task;
168164
if (payload.text.length > 1 && payload.text[0] === ">") {
169165
payload.text = encode(payload.text.substr(1));

scripts/fb_revealDeletedMessages.js

Lines changed: 110 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ export default {
2121
// });
2222
// return websocket_instant;
2323
// };
24-
2524
// window.WebSocket.prototype = WebSocketOrig.prototype;
2625
// window.WebSocket.prototype.constructor = window.WebSocket;
27-
2826
// window.addEventListener(
2927
// "message",
3028
// function (t) {
@@ -33,68 +31,128 @@ export default {
3331
// !1
3432
// );
3533

36-
// console.log(window.__d);
37-
// let emptyFunc = void 0;
38-
// Object.defineProperty(window, "__d", {
39-
// get: () => emptyFunc,
40-
// set: (i) => {
41-
// const c = new Proxy(i, {
42-
// apply: async function (moduleName, dependencies, args) {
43-
// console.log(arguments);
44-
// // return moduleName(...args);
45-
// return i.apply(this, arguments);
46-
// },
47-
// });
48-
// emptyFunc = c;
49-
// },
50-
// });
34+
let emptyFunc = void 0;
35+
Object.defineProperty(window, "__d", {
36+
get: () => emptyFunc,
37+
set: (i) => {
38+
const c = new Proxy(i, {
39+
apply: function (target, thisArg, arg) {
40+
console.log(thisArg);
41+
return target(...arg);
42+
},
43+
});
44+
emptyFunc = c;
45+
},
46+
});
5147
},
5248

5349
onDocumentIdle: () => {
54-
// MWV2ChatImage.bs
55-
requireLazy(["MWV2ChatUnsentMessage.bs"], (MWV2ChatUnsentMessage) => {
56-
const MWV2ChatUnsentMessageOrig = MWV2ChatUnsentMessage.make;
50+
// tất cả loại tin nhắn đều được bao bọc bởi:
51+
// MWPBaseMessage.bs
52+
// MWMessageListAttachment.bs
53+
// MWMessageListAttachmentContainer.bs
54+
55+
let key = "ufs_reveal_deleted_fb_messages";
56+
let savedMessages = JSON.parse(localStorage.getItem(key) ?? "[]");
57+
58+
console.log(
59+
"Load " + savedMessages.length + " messages from localStorage."
60+
);
5761

58-
MWV2ChatUnsentMessage.make = function (a) {
59-
if (a) {
60-
let outgoing = a.outgoing;
61-
let {
62-
isUnsent,
63-
messageId,
64-
threadKey,
65-
offlineThreadingId,
66-
displayedContentTypes,
67-
senderId,
68-
} = a.message;
62+
requireLazy(
63+
["MWV2ChatUnsentMessage.bs", "MWPBaseMessage.bs", "MqttProtocolClient"],
64+
(MWV2ChatUnsentMessage, MWPBaseMessage, MqttProtocolClient) => {
65+
// Override unsent message component
66+
const MWV2ChatUnsentMessageOrig = MWV2ChatUnsentMessage.make;
67+
MWV2ChatUnsentMessage.make = function (a) {
68+
if (a) {
69+
let outgoing = a.outgoing;
70+
let {
71+
isUnsent,
72+
messageId,
73+
threadKey,
74+
offlineThreadingId,
75+
displayedContentTypes,
76+
senderId,
77+
} = a.message;
6978

70-
if (isUnsent) {
71-
threadKey =
72-
UsefulScriptGlobalWebpageContext.Facebook.decodeArrId(threadKey);
73-
senderId =
74-
UsefulScriptGlobalWebpageContext.Facebook.decodeArrId(senderId);
79+
if (isUnsent) {
80+
threadKey =
81+
UsefulScriptGlobalWebpageContext.Facebook.decodeArrId(
82+
threadKey
83+
);
84+
senderId =
85+
UsefulScriptGlobalWebpageContext.Facebook.decodeArrId(senderId);
7586

76-
a.message.isUnsent = false;
77-
a.message.text = "[Hacked]: thu hồi nè";
87+
a.message.isUnsent = false;
88+
a.message.text = "[Hacked]: thu hồi nè";
7889

79-
console.log(
80-
"Tin nhắn thu hồi từ " + senderId + " trong " + threadKey,
81-
a
82-
);
90+
console.log(
91+
"Tin nhắn thu hồi từ " + senderId + " trong " + threadKey,
92+
a
93+
);
94+
}
8395
}
84-
}
85-
return MWV2ChatUnsentMessageOrig.apply(this, arguments);
86-
};
87-
});
96+
return MWV2ChatUnsentMessageOrig.apply(this, arguments);
97+
};
98+
99+
// Listen for chat event
100+
const MqttProtocolClientOrig = MqttProtocolClient.prototype.publish;
101+
MqttProtocolClient.prototype.publish = function () {
102+
let b = arguments[1];
103+
console.log(b);
104+
// if (b && b.includes('\\\\\\"text\\\\\\":')) {
105+
// (function () {
106+
// b = JSON.parse(b);
107+
// if (!b || !b.payload) return;
108+
// let payload = JSON.parse(b.payload);
109+
// if (!payload || !payload.tasks) return;
110+
111+
// payload.tasks = payload.tasks.map((task) => {
112+
// let payload = JSON.parse(task.payload);
113+
// if (!payload || !payload.text) return task;
114+
// if (payload.text.length > 1 && payload.text[0] === ">") {
115+
// payload.text = encode(payload.text.substr(1));
116+
// }
117+
// task.payload = JSON.stringify(payload);
118+
// return task;
119+
// });
120+
121+
// b.payload = JSON.stringify(payload);
122+
// b = JSON.stringify(b);
123+
// })();
124+
// arguments[1] = b;
125+
// }
126+
return MqttProtocolClientOrig.apply(this, arguments);
127+
};
128+
}
129+
);
88130

89131
// Test who is typing
132+
// MWChatTypingIndicator.bs
133+
// MWPTypingIndicators.bs
90134
requireLazy(["LSUpdateTypingIndicator"], (LSUpdateTypingIndicator) => {
91-
const LSUpdateTypingIndicatorOrig = LSUpdateTypingIndicator;
92-
console.log("abc");
135+
alert("abc");
136+
// const LSUpdateTypingIndicatorOrig = LSUpdateTypingIndicator;
137+
138+
// LSUpdateTypingIndicator = function () {
139+
// console.log(arguments);
140+
// return LSUpdateTypingIndicatorOrig.apply(this, arguments);
141+
// };
142+
});
93143

94-
LSUpdateTypingIndicator = function (...args) {
95-
console.log(args);
96-
return LSUpdateTypingIndicatorOrig.apply(this, arguments);
97-
};
144+
let emptyFunc = void 0;
145+
Object.defineProperty(window, "__d", {
146+
get: () => emptyFunc,
147+
set: (i) => {
148+
const c = new Proxy(i, {
149+
apply: function (target, thisArg, arg) {
150+
console.log(thisArg);
151+
return target(...arg);
152+
},
153+
});
154+
emptyFunc = c;
155+
},
98156
});
99157
},
100158
};

0 commit comments

Comments
 (0)