Skip to content

Commit 1c10ac7

Browse files
author
hoang.tran12
committed
track settimeout + fix get fb token, get fb album
1 parent 6e549d8 commit 1c10ac7

File tree

7 files changed

+80
-36
lines changed

7 files changed

+80
-36
lines changed

content-scripts/document_start.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,15 @@ function injectScriptFile(filePathOrUrl, isExternal = false) {
1919
}
2020
}
2121

22-
injectScriptFile("/content-scripts/globals_debugger.js");
23-
injectScriptFile("/content-scripts/useful-scripts-utils.js");
22+
const CONFIG = {
23+
enableUsefulScriptUtils: true,
24+
};
25+
26+
if (CONFIG.enableUsefulScriptUtils) {
27+
// injectScriptFile("/content-scripts/track_settimeout.js");
28+
// injectScriptFile("/content-scripts/globals_debugger.js");
29+
injectScriptFile("/content-scripts/useful-scripts-utils.js");
30+
}
2431

2532
if (location.hostname === "mp3.zing.vn")
2633
injectScriptFile("/content-scripts/mp3.zing.vn.js");

content-scripts/mp3.zing.vn.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
// prevent auto redirect from https://mp3.zing.vn/ to https://zingmp3.vn/
22
window.MP3_MEDIA_USER_UPLOAD = 1;
33

4+
// mp3 VIP (test)
45
window.onload = () => {
56
if (window.MP3) {
67
window.MP3.ACCOUNT_ID = new Date().getTime();
78
window.MP3.ACCOUNT_NAME = "VIP - Useful scripts";
89
window.MP3.VIP = 1;
9-
window.MP3.IS_IP_VN = false;
10+
window.MP3.IS_IP_VN = true;
1011
}
1112

1213
window.checkLogin = () => true;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// https://stackoverflow.com/a/858638
2+
3+
window.originalSetTimeout = window.setTimeout;
4+
window.originalClearTimeout = window.clearTimeout;
5+
6+
const useful_scripts_track_settimeout = {
7+
currentId: 0,
8+
activeTimers: [],
9+
};
10+
11+
window.setTimeout = function (func, delay) {
12+
useful_scripts_track_settimeout.activeTimers.push({
13+
id: useful_scripts_track_settimeout.currentId++,
14+
func: func,
15+
funcStr: func.toString(),
16+
});
17+
return window.originalSetTimeout(func, delay);
18+
};
19+
20+
window.clearTimeout = function (timerID) {
21+
useful_scripts_track_settimeout.activeTimers =
22+
useful_scripts_track_settimeout.activeTimers.filter(
23+
(_) => _.id !== useful_scripts_track_settimeout.currentId
24+
);
25+
useful_scripts_track_settimeout.currentId--;
26+
window.originalClearTimeout(timerID);
27+
};

scripts/fb_getAllAlbumId.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default {
1414
// Lấy tất cả album id có trong trang web - Khi đang xem 1 danh sách album của user/group/page
1515

1616
const list_a = document.querySelectorAll("a");
17-
const list_id = [];
17+
let list_id = [];
1818
for (let a of [location, ...Array.from(list_a)]) {
1919
const page_album_id = /(?<=\/photos\/a\.)(.\d+?)(?=\/)/.exec(a.href);
2020
if (page_album_id && page_album_id[0]) {
@@ -29,6 +29,8 @@ export default {
2929
list_id.push(user_album_id[0]);
3030
}
3131
}
32+
// filter duplicate: https://stackoverflow.com/a/14438954
33+
list_id = [...new Set(list_id)];
3234
if (list_id.length)
3335
window.prompt(
3436
`Tìm thấy ${list_id.length} album id trong trang web và trên url.`,

scripts/fb_getTimelineAlbumId.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
export default {
22
name: {
3-
en: "Get timeline Album ID of fb page",
4-
vi: "Tìm timeline album id của fb page",
3+
en: "Get id of fb timeline album",
4+
vi: "Tìm id của album fb chứa mọi ảnh tải lên",
55
},
66
description: {
7-
en: "Get timeline album id of page in current website",
8-
vi: "Tìm timeline album id của page hiện tại",
7+
en: "Get timeline album id of page/user in current website",
8+
vi: "Tìm album chứa tất cả ảnh trên dòng thời gian của page/user hiện tại",
99
},
1010
blackList: [],
1111
whiteList: ["*://www.facebook.com"],
@@ -18,14 +18,16 @@ export default {
1818
for (let a of Array.from(list_a)) {
1919
const posts_screen = /(?<=set\=a\.)(.\d+?)(?=\&__cft__)/.exec(a.href);
2020
if (posts_screen && posts_screen[0]) {
21-
window.prompt(`Timeline Album ID của ${page_name}:`, posts_screen[0]) &&
22-
window.open("https://www.facebook.com/" + posts_screen[0]);
21+
window.prompt(
22+
`Timeline Album ID của ${page_name}:\n` +
23+
"- Bấm OK để mở album trong tab mới. Cancel để huỷ -",
24+
posts_screen[0]
25+
) && window.open("https://www.facebook.com/" + posts_screen[0]);
2326
return;
2427
}
2528
}
26-
window.prompt(
27-
"Không tìm thấy TIMELINE ALBUM trong trang web!\nBạn có đang ở đúng trang web của 1 Page fb chưa?\nThử kéo xuống tới bài post nào có kèm hình ảnh rồi ấn lại bookmark nhé\nTrang web Ví dụ: ",
28-
"https://www.facebook.com/profile.php?id=100057998562930"
29+
window.alert(
30+
"Không tìm thấy TIMELINE ALBUM trong trang web!\nBạn có đang ở đúng trang web của 1 Page/User fb chưa?"
2931
);
3032
},
3133
};

scripts/fb_getTokenFacebook.js

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,39 @@ export default {
1212
whiteList: ["*://www.facebook.com"],
1313

1414
func: function () {
15-
var uid = /(?<=c_user=)(\d+)/.exec(document.cookie)[0],
16-
dtsg =
17-
require("DTSGInitialData").token ||
18-
document.querySelector('[name="fb_dtsg"]').value,
19-
http = new XMLHttpRequest(),
20-
url = "//www.facebook.com/v1.0/dialog/oauth/confirm",
21-
params =
22-
"fb_dtsg=" +
23-
dtsg +
24-
"&app_id=124024574287414&redirect_uri=fbconnect%3A%2F%2Fsuccess&display=page&access_token=&from_post=1&return_format=access_token&domain=&sso_device=ios&_CONFIRM=1&_user=" +
25-
uid;
26-
http.open("POST", url, !0),
27-
http.setRequestHeader(
28-
"Content-type",
29-
"application/x-www-form-urlencoded"
30-
),
31-
(http.onreadystatechange = function () {
32-
if (4 == http.readyState && 200 == http.status) {
33-
var a = http.responseText.match(/(?<=access_token=)(.*?)(?=\&)/);
34-
console.log(http.responseText);
15+
try {
16+
let uid = /(?<=c_user=)(\d+)/.exec(document.cookie)?.[0];
17+
if (!uid) {
18+
alert("Không tìm thấy uid trong cookie. Bạn đã đăng nhập chưa?");
19+
return;
20+
}
21+
let dtsg =
22+
require("DTSGInitialData").token ||
23+
document.querySelector('[name="fb_dtsg"]').value,
24+
xhr = new XMLHttpRequest(),
25+
url = "//www.facebook.com/v1.0/dialog/oauth/confirm",
26+
params =
27+
"fb_dtsg=" +
28+
dtsg +
29+
"&app_id=124024574287414&redirect_uri=fbconnect%3A%2F%2Fsuccess&display=page&access_token=&from_post=1&return_format=access_token&domain=&sso_device=ios&_CONFIRM=1&_user=" +
30+
uid;
31+
xhr.open("POST", url, !0);
32+
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
33+
xhr.onreadystatechange = function () {
34+
if (4 == xhr.readyState && 200 == xhr.status) {
35+
var a = xhr.responseText.match(/(?<=access_token=)(.*?)(?=\&)/);
36+
console.log(xhr.responseText);
3537
if (a && a[0]) {
3638
prompt("Token", a[0]);
3739
} else {
3840
alert("Failed to Get Access Token.");
3941
}
4042
}
41-
}),
42-
http.send(params);
43+
};
44+
xhr.send(params);
45+
} catch (e) {
46+
alert("ERROR: " + e);
47+
}
4348
},
4449
};
4550

scripts/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ const allScripts = {
118118
fb_getPageId: addBadge(fb_getPageId, BADGES.hot),
119119
fb_getGroupId: addBadge(fb_getGroupId, BADGES.hot),
120120
fb_getAlbumId: addBadge(fb_getAlbumId, BADGES.hot),
121-
fb_getTimelineAlbumId,
121+
fb_getTimelineAlbumId: addBadge(fb_getTimelineAlbumId, BADGES.hot),
122122
fb_getAllVideoId,
123123
fb_getAllAlbumId,
124124
fb_getUidFromUrl: addBadge(fb_getUidFromUrl, BADGES.hot),

0 commit comments

Comments
 (0)