Skip to content

Commit 9c0c0b8

Browse files
committed
UI to display results
1 parent 64d4093 commit 9c0c0b8

File tree

8 files changed

+308
-6
lines changed

8 files changed

+308
-6
lines changed

scripts/content-scripts/scripts/ufs_global_webpage_context.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,12 +784,14 @@ const UsefulScriptGlobalPageContext = {
784784
image: e.node.image.uri,
785785
cursor: e.cursor,
786786
})),
787+
totalCount: items.count,
787788
};
788789
} catch (e) {
789790
console.log("ERROR fetch page", e);
790791
return {
791792
nextCursor: null,
792793
data: [],
794+
totalCount: 0,
793795
};
794796
}
795797
},
@@ -798,7 +800,7 @@ const UsefulScriptGlobalPageContext = {
798800
let allPages = [];
799801
try {
800802
while (true) {
801-
let { nextCursor, data } =
803+
let { nextCursor, data, totalCount } =
802804
await UsefulScriptGlobalPageContext.Facebook.searchPageForOther(
803805
other_uid,
804806
cursor,
@@ -807,7 +809,7 @@ const UsefulScriptGlobalPageContext = {
807809
);
808810
cursor = nextCursor;
809811
allPages = allPages.concat(data);
810-
await pageFetchedCallback?.(data, allPages);
812+
await pageFetchedCallback?.(data, allPages, totalCount);
811813

812814
if (!cursor) break;
813815
}

scripts/fb_messengerCount_main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ function numberWithCommas(x) {
99
function main() {
1010
try {
1111
let data = JSON.parse(localStorage.ufs_fb_msg_kount) || [];
12+
console.log(data);
1213

1314
searchCount.innerHTML = data.length;
1415

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Facebook - Xem các nhóm mà bạn bè tham gia</title>
8+
9+
<style>
10+
body {
11+
margin: auto;
12+
max-width: 700px;
13+
}
14+
15+
h1 {
16+
text-align: center;
17+
}
18+
19+
table {
20+
font-family: arial, sans-serif;
21+
border-collapse: collapse;
22+
width: 100%;
23+
font-size: 1.2em;
24+
margin: auto;
25+
margin-bottom: 100px;
26+
}
27+
28+
td,
29+
th {
30+
border: 1px solid #dddddd;
31+
padding: 8px;
32+
}
33+
34+
tr:nth-child(even) {
35+
background-color: #dddddd;
36+
}
37+
38+
tr.hidden {
39+
display: none;
40+
}
41+
42+
table a {
43+
text-decoration: none;
44+
}
45+
46+
table a:hover {
47+
text-decoration: underline;
48+
}
49+
50+
#searchCount {
51+
font-weight: bold;
52+
}
53+
54+
.center {
55+
text-align: center;
56+
font-size: 1.5em;
57+
}
58+
</style>
59+
</head>
60+
61+
<body>
62+
<h1>Useful script</h1>
63+
<h1>Facebook - Xem các nhóm mà bạn bè tham gia</h1>
64+
<p class="center">Tìm thấy <span id="searchCount">~</span> nhóm.</p>
65+
<input id="search-inp" type="text" placeholder="Tìm theo tên, rank, count, group...">
66+
<table id="table"></table>
67+
<script src="./fb_searchGroupForOther_main.js"></script>
68+
</body>
69+
70+
</html>

scripts/fb_searchGroupForOther.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ export default {
3737
}
3838
);
3939
console.log(allGroups);
40+
localStorage.ufs_fb_searchGroupForOther = JSON.stringify(allGroups);
41+
window.open(
42+
await UsefulScriptGlobalPageContext.Extension.getURL(
43+
"scripts/fb_searchGroupForOther.html"
44+
)
45+
);
4046
} catch (e) {
4147
alert("ERROR: " + e);
4248
} finally {
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
const inputSearch = document.querySelector("#search-inp");
2+
const tableDiv = document.querySelector("table");
3+
const searchCount = document.querySelector("#searchCount");
4+
5+
function numberWithCommas(x) {
6+
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
7+
}
8+
9+
function main() {
10+
try {
11+
let data = JSON.parse(localStorage.ufs_fb_searchGroupForOther) || [];
12+
console.log(data);
13+
14+
searchCount.innerHTML = data.length;
15+
16+
tableDiv.innerHTML = `
17+
<tr>
18+
<th>STT</th>
19+
<th>Ảnh</th>
20+
<th>Tên</th>
21+
<th>Thành viên</th>
22+
</tr>
23+
${data
24+
.map((c, i) => {
25+
let link = `https://fb.com/${c.id}`;
26+
27+
return `<tr>
28+
<td>${i + 1}</td>
29+
<td><img src="${c.image}" style="max-height: 80px"></img></td>
30+
<td>
31+
<a style="font-size: 1.1em" href="${link}" target="_blank">${
32+
c.title
33+
}</a>
34+
<br/>
35+
<span>${c.subTitle?.split?.("\n")?.[1] || ""}</span>
36+
</td>
37+
<td>${numberWithCommas(c.membersCount)}</td>
38+
</tr>`;
39+
})
40+
.join("")}
41+
`;
42+
43+
inputSearch.oninput = (e) => {
44+
search(inputSearch.value);
45+
};
46+
} catch (e) {
47+
alert("ERROR: " + e);
48+
}
49+
}
50+
51+
function search(text) {
52+
let count = 0;
53+
[...tableDiv.querySelectorAll("tr")].forEach((tr, index) => {
54+
if (index == 0) return; // ignore table header
55+
56+
let html = tr.innerHTML;
57+
if (!html.toLowerCase().includes(text.toLowerCase())) {
58+
tr.classList.add("hidden");
59+
} else {
60+
tr.classList.remove("hidden");
61+
count++;
62+
}
63+
});
64+
searchCount.innerHTML = count;
65+
}
66+
67+
main();

scripts/fb_searchPageForOther.html

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Facebook - Xem các nhóm mà bạn bè tham gia</title>
8+
9+
<style>
10+
body {
11+
margin: auto;
12+
max-width: 700px;
13+
}
14+
15+
h1 {
16+
text-align: center;
17+
}
18+
19+
table {
20+
font-family: arial, sans-serif;
21+
border-collapse: collapse;
22+
width: 100%;
23+
font-size: 1.2em;
24+
margin: auto;
25+
margin-bottom: 100px;
26+
}
27+
28+
td,
29+
th {
30+
border: 1px solid #dddddd;
31+
padding: 8px;
32+
}
33+
34+
tr:nth-child(even) {
35+
background-color: #dddddd;
36+
}
37+
38+
tr.hidden {
39+
display: none;
40+
}
41+
42+
table a {
43+
text-decoration: none;
44+
}
45+
46+
table a:hover {
47+
text-decoration: underline;
48+
}
49+
50+
#searchCount {
51+
font-weight: bold;
52+
}
53+
54+
.center {
55+
text-align: center;
56+
font-size: 1.5em;
57+
}
58+
</style>
59+
</head>
60+
61+
<body>
62+
<h1>Useful script</h1>
63+
<h1>Facebook - Xem các trang mà bạn bè thích</h1>
64+
<p class="center"><span id="owner"></span> đã thích <span id="searchCount">~</span> trang.</p>
65+
<input id="search-inp" type="text" placeholder="Tìm kiếm...">
66+
<table id="table"></table>
67+
<script src="./fb_searchPageForOther_main.js"></script>
68+
</body>
69+
70+
</html>

scripts/fb_searchPageForOther.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,41 @@ export default {
1717

1818
let { setLoadingText, closeLoading } = showLoading("Đang chuẩn bị...");
1919
try {
20-
let { getUidFromUrl, getYourUserId, getFbdtsg, searchAllPageForOther } =
21-
UsefulScriptGlobalPageContext.Facebook;
20+
let {
21+
getUidFromUrl,
22+
getYourUserId,
23+
getFbdtsg,
24+
searchAllPageForOther,
25+
getUserInfoFromUid,
26+
} = UsefulScriptGlobalPageContext.Facebook;
2227

2328
setLoadingText("Đang lấy uid, token...");
2429
let other_uid = await getUidFromUrl(url);
2530
let uid = await getYourUserId();
2631
let dtsg = await getFbdtsg();
32+
let info = await getUserInfoFromUid(other_uid);
33+
console.log(info);
2734

2835
setLoadingText("Đang tải danh sách page...");
2936
let allPages = await searchAllPageForOther(
3037
other_uid,
3138
uid,
3239
dtsg,
33-
(pages, all) => {
40+
(pages, all, totalCount) => {
3441
setLoadingText(
35-
`Đang tải danh sách page...<br/>Tải được ${all.length} page.`
42+
`Đang tải danh sách page...<br/>Tải được ${all.length}/${totalCount} page.`
3643
);
3744
}
3845
);
3946
console.log(allPages);
47+
localStorage.ufs_fb_searchPageForOther = JSON.stringify(allPages);
48+
localStorage.ufs_fb_searchPageForOther_owner = JSON.stringify(info);
49+
50+
window.open(
51+
await UsefulScriptGlobalPageContext.Extension.getURL(
52+
"scripts/fb_searchPageForOther.html"
53+
)
54+
);
4055
} catch (e) {
4156
alert("ERROR: " + e);
4257
} finally {
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
const inputSearch = document.querySelector("#search-inp");
2+
const tableDiv = document.querySelector("table");
3+
const searchCount = document.querySelector("#searchCount");
4+
const ownerLink = document.querySelector("#owner");
5+
6+
function numberWithCommas(x) {
7+
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
8+
}
9+
10+
function main() {
11+
try {
12+
let data = JSON.parse(localStorage.ufs_fb_searchPageForOther) || [];
13+
let owner = JSON.parse(localStorage.ufs_fb_searchPageForOther_owner) || {};
14+
console.log(data, owner);
15+
16+
let link = "https://fb.com/" + owner.uid;
17+
ownerLink.innerHTML = `
18+
<a href="${link}" target="_blank" style="display: inline-block;">
19+
<img style="max-height: 80px;border-radius: 50%" src="${owner.avatar}" />
20+
${owner.name}
21+
</a>`;
22+
searchCount.innerHTML = data.length;
23+
24+
tableDiv.innerHTML = `
25+
<tr>
26+
<th>STT</th>
27+
<th>Ảnh</th>
28+
<th>Tên</th>
29+
</tr>
30+
${data
31+
.map((c, i) => {
32+
return `<tr>
33+
<td>${i + 1}</td>
34+
<td><img src="${c.image}" style="max-height: 80px"></img></td>
35+
<td>
36+
<a style="font-size: 1.1em" href="${c.url}" target="_blank">${
37+
c.name
38+
}</a>
39+
<br/>
40+
<span>${c.subTitle?.split?.("\n")?.[1] || ""}</span>
41+
</td>
42+
</tr>`;
43+
})
44+
.join("")}
45+
`;
46+
47+
inputSearch.oninput = (e) => {
48+
search(inputSearch.value);
49+
};
50+
} catch (e) {
51+
alert("ERROR: " + e);
52+
}
53+
}
54+
55+
function search(text) {
56+
let count = 0;
57+
[...tableDiv.querySelectorAll("tr")].forEach((tr, index) => {
58+
if (index == 0) return; // ignore table header
59+
60+
let html = tr.innerHTML;
61+
if (!html.toLowerCase().includes(text.toLowerCase())) {
62+
tr.classList.add("hidden");
63+
} else {
64+
tr.classList.remove("hidden");
65+
count++;
66+
}
67+
});
68+
searchCount.innerHTML = count;
69+
}
70+
71+
main();

0 commit comments

Comments
 (0)