Skip to content

Commit 6e549d8

Browse files
committed
loading UI + transfer.sh (WIP)
1 parent ec6f4ac commit 6e549d8

19 files changed

+418
-65
lines changed

popup/tabs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ const tabs = [
148148
{
149149
...CATEGORY.automation,
150150
scripts: [
151+
s.transfer_sh,
151152
s.textToQRCode,
152153
s.webToQRCode,
153154
s.getAllEmailsInWeb,

scripts/fb_downloadAlbumMedia.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { showLoading } from "./helpers/utils.js";
2+
13
export default {
24
name: {
35
en: "Download fb album media links",
@@ -14,6 +16,7 @@ export default {
1416
if (!accessToken) return;
1517
const albumId = prompt("Enter album id: ", "");
1618
if (!albumId) return;
19+
1720
async function fetchAlbumPhotosFromCursor({ albumId, cursor }) {
1821
let url = `https://graph.facebook.com/v12.0/${albumId}/photos?fields=largest_image&limit=100&access_token=${accessToken}`;
1922
if (cursor) url += `&after=${cursor}`;
@@ -64,7 +67,11 @@ export default {
6467
}
6568
return allImgsData;
6669
}
67-
async function fetchAllPhotoLinksInAlbum({ albumId, fromPhotoId }) {
70+
async function fetchAllPhotoLinksInAlbum({
71+
albumId,
72+
fromPhotoId,
73+
progress,
74+
}) {
6875
const from_text = fromPhotoId
6976
? "vị trí photo_id=" + fromPhotoId
7077
: "đầu album";
@@ -75,6 +82,7 @@ export default {
7582
fromPhotoId,
7683
pageFetchedCallback: (pageImgsData) => {
7784
result.push(...pageImgsData.map((_) => _.url));
85+
progress?.(result.length);
7886
},
7987
});
8088
return result;
@@ -96,8 +104,17 @@ export default {
96104
}, 0);
97105
}
98106
}
99-
fetchAllPhotoLinksInAlbum({ albumId }).then((links) => {
107+
108+
const { closeLoading, setLoadingText } = showLoading(
109+
"Đang thu thập link ảnh/video trong album..."
110+
);
111+
fetchAllPhotoLinksInAlbum({
112+
albumId,
113+
progress: (length) =>
114+
setLoadingText("Đang thu thập " + length + " links..."),
115+
}).then((links) => {
100116
download(links.join("\n"), albumId, ".txt");
117+
closeLoading();
101118
});
102119
},
103120
};

scripts/fb_getAvatarFromUid.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { showLoading } from "./helpers/utils.js";
2+
13
export default {
24
name: {
35
en: "Get avatar from fb user id",
@@ -14,17 +16,29 @@ export default {
1416
if (!accessToken) return;
1517
let uids = prompt("Nhập danh sách uid, Mỗi uid 1 dòng:");
1618
if (!uids) return;
17-
uids = uids.split("\n");
18-
let urls = [];
19-
for (let uid of uids) {
20-
console.log("fetching avatar of " + uid + "...");
21-
let url = `https://graph.facebook.com/${uid}/picture?type=large&access_token=${accessToken}`;
22-
let data = await fetch(url);
23-
if (data?.url) {
24-
urls.push(data?.url);
19+
20+
const { closeLoading, setLoadingText } = showLoading();
21+
try {
22+
uids = uids.split("\n");
23+
let urls = [];
24+
for (let uid of uids) {
25+
setLoadingText("Đang lấy avatar của " + uid + "...");
26+
let url = `https://graph.facebook.com/${uid}/picture?type=large&access_token=${accessToken}`;
27+
let data = await fetch(url);
28+
if (data?.url) {
29+
urls.push(data?.url);
30+
}
2531
}
32+
} catch (e) {
33+
alert("ERROR: " + e);
34+
} finally {
35+
closeLoading();
2636
}
27-
download(urls.join("\n"), `uid-${new Date().toLocaleString()}.txt`);
37+
38+
if (urls.length === 0) alert("Không tìm được avatar nào!");
39+
else if (urls.length === 1) window.open(urls[0]);
40+
else download(urls.join("\n"), `uid-${new Date().toLocaleString()}.txt`);
41+
2842
function download(data, filename, type) {
2943
var file = new Blob([data], { type: type });
3044
if (window.navigator.msSaveOrOpenBlob)

scripts/fb_getTokenBusinessStudio.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { showLoading } from "./helpers/utils.js";
2+
13
export default {
24
icon: `<i class="fa-solid fa-key"></i>`,
35
name: {
@@ -22,6 +24,9 @@ export default {
2224
// alert("LỖI: " + e.message);
2325
// }
2426

27+
const { closeLoading, setLoadingText } = showLoading(
28+
"Đang tìm access token..."
29+
);
2530
fetch("https://business.facebook.com/creatorstudio/home", {
2631
method: "GET",
2732
credentials: "include",
@@ -40,6 +45,9 @@ export default {
4045
})
4146
.catch(function (e) {
4247
alert("ERROR:" + JSON.stringify(e));
48+
})
49+
.finally(() => {
50+
closeLoading();
4351
});
4452
},
4553
};

scripts/fb_getTokenBussinessLocation.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { showLoading } from "./helpers/utils.js";
2+
13
export default {
24
icon: `<i class="fa-solid fa-key"></i>`,
35
name: {
@@ -14,6 +16,7 @@ export default {
1416
func: function () {
1517
// Get token using cookies https://github.com/dz-id/fb_get_token_from_cookie/blob/main/main.py
1618

19+
const { closeLoading } = showLoading("Đang lấy access token...");
1720
fetch("https://business.facebook.com/business_locations")
1821
.then((res) => res.text())
1922
.then((htmlText) => {
@@ -28,7 +31,8 @@ export default {
2831
);
2932
}
3033
})
31-
.catch((e) => alert("Error: " + e));
34+
.catch((e) => alert("Error: " + e))
35+
.finally(closeLoading);
3236
},
3337
};
3438

scripts/fb_getTokenCampaigns.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { showLoading } from "./helpers/utils.js";
2+
13
export default {
24
icon: `<i class="fa-solid fa-key"></i>`,
35
name: {
@@ -50,12 +52,14 @@ export default {
5052
}
5153

5254
(async () => {
55+
const { closeLoading } = showLoading("Đang lấy access token...");
5356
let token = await getToken();
5457
if (token) {
5558
window.prompt("Access token: ", token);
5659
} else {
5760
alert("Không tìm thấy access token");
5861
}
62+
closeLoading();
5963
})();
6064
},
6165
};

scripts/fb_getTokenFfb.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { showLoading } from "./helpers/utils.js";
2+
13
export default {
24
icon: "https://ffb.vn/assets/img/illustrations/favicon.png",
35
name: {
@@ -19,6 +21,8 @@ export default {
1921
}
2022

2123
(async () => {
24+
const { closeLoading, setLoadingText } =
25+
showLoading("Đang lấy cookie...");
2226
let cookie = await getCookiesInExtensionContext("facebook.com");
2327
if (!cookie) {
2428
alert("Không thấy cookie. Hãy chắc rằng bạn đã đăng nhập facebook!");
@@ -51,6 +55,7 @@ export default {
5155
formData.append("cookie", cookie);
5256
formData.append("type", types[typeIndex]);
5357

58+
setLoadingText("Đang lấy accesstoken từ ffb.vn ...");
5459
let res = await fetch("https://ffb.vn/api/tool/cookie2token", {
5560
method: "POST",
5661
body: formData,
@@ -62,6 +67,7 @@ export default {
6267
prompt("Access token", json.token);
6368
}
6469
}
70+
closeLoading();
6571
})();
6672
},
6773
};

scripts/fb_getTokenMFacebook.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { showLoading } from "./helpers/utils.js";
2+
13
export default {
24
icon: `<i class="fa-solid fa-key"></i>`,
35
name: {
@@ -11,7 +13,7 @@ export default {
1113
runInExtensionContext: true,
1214

1315
func: function () {
14-
console.log("Đang lấy token ...");
16+
const { closeLoading, setLoadingText } = showLoading("Đang lấy token ...");
1517
fetch("https://m.facebook.com/composer/ocelot/async_loader/?publisher=feed")
1618
.then((response) => response.text())
1719
.then((text) => {
@@ -33,6 +35,7 @@ export default {
3335
})
3436
.catch((e) => {
3537
alert("ERROR: " + e.message);
36-
});
38+
})
39+
.finally(closeLoading);
3740
},
3841
};

scripts/fb_getUidFromUrl.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { showLoading } from "./helpers/utils.js";
2+
13
export default {
24
name: {
35
en: "Get fb User ID from url",
@@ -24,12 +26,15 @@ export default {
2426
return null;
2527
};
2628
const url = window.prompt("Nhập url của user fb:", "");
27-
if (url)
29+
if (url) {
30+
const { closeLoading } = showLoading("Đang lấy UID của " + url);
2831
_getUidFromUrl(url)
2932
.then((uid) => {
3033
if (uid) window.prompt(`UID của user ${url}:`, uid);
3134
else alert("Không tìm thấy uid của user!");
3235
})
33-
.catch((err) => alert("Lỗi: " + err.message));
36+
.catch((err) => alert("Lỗi: " + err.message))
37+
.finally(closeLoading);
38+
}
3439
},
3540
};

scripts/getFavicon.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@ export default {
6161
"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=400,height=500,top=50,left=50"
6262
);
6363
win.document.title = location.hostname + " favicons";
64-
win.document.body.innerHTML = `<div>
64+
65+
// https://stackoverflow.com/a/69309927/11898496
66+
let escapeHTMLPolicy = trustedTypes.createPolicy("forceInner", {
67+
createHTML: (to_escape) => to_escape,
68+
});
69+
win.document.body.innerHTML = escapeHTMLPolicy.createHTML(`<div>
6570
<style>
6671
.container {
6772
text-align: center;
@@ -80,6 +85,6 @@ export default {
8085
${allFaviconsStr}
8186
</div>
8287
</div>
83-
`;
88+
`);
8489
},
8590
};

0 commit comments

Comments
 (0)