forked from J2TeamNNL/J2Team-Community
-
Notifications
You must be signed in to change notification settings - Fork 0
/
count_reaction_post.html
151 lines (148 loc) · 4.18 KB
/
count_reaction_post.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<!DOCTYPE html>
<html>
<head>
<title>Count Reaction Post</title>
</head>
<body>
<h3>Nhập token của bạn: <a href="https://fb.com/me" target="_blank"> (ấn vào đây (trang cá nhân) => Ctrl U => Ctrl F => gõ EAAA => đoạn EAAA... đó là token )</a></h3>
<input type="text" id="token" placeholder="EAAA..." value=""><br>
<h3>Nhập id trang (hoặc nhóm, hoặc cá nhân): <a href="https://findmyfbid.com" target="_blank">Tìm trên findmyfbid.com</a></h3>
<input type="number" id="id_object" placeholder="1000...." value=""><br>
<h3>Nhập id bài đăng, mỗi id xuống dòng nhé</h3><textarea cols="50" rows="10" placeholder="10000000
20000000"></textarea>
<br>
<button>OK</button>
<h1>Danh sách đã lọc</h1>
<table>
<thead>
<th>
STT
</th>
<th>
ID Bài Đăng
</th>
<th>
Like
</th>
<th>
Comment
</th>
<th>
Share
</th>
</thead>
</table>
<!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> -->
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.10.18/datatables.min.css"/>
<script type="text/javascript" src="https://cdn.datatables.net/v/dt/dt-1.10.18/datatables.min.js"></script>
<script>
Array.prototype.unique = function() {
return Array.from(new Set(this));
}
let token, id_object, array_id, array_index = [], array_share = [], array_like = [], array_comment = [], array_unique = [], activeAjaxConnections = [], index_post = 0;
var t = $('table').DataTable();
$(document).ready(function(){
$("button").click(function(e){
e.stopPropagation();
token = $("#token").val();
id_object = $("#id_object").val();
array_id = $("textarea").val().split("\n");
$.each(array_id, function(index,id_post){
index_post++;
id_post = `${id_object}_${id_post}`;
link = `https://graph.facebook.com/${id_post}/sharedposts?limit=1000&fields=from.id&access_token=${token}`;
array_share[id_post] = [];
array_like[id_post] = 0;
array_comment[id_post] = 0;
activeAjaxConnections[id_post] = 3;
array_index[id_post] = index_post;
getShare(link,id_post);
getLike(id_post);
getComment(id_post);
});
});
});
function getShare(link,id_post){
$.ajax({
url: link,
dataType: 'json',
})
.success(function(response) {
$.each(response.data, function(index,each){
array_share[id_post].push(each.from.id);
});
if(response.paging){
if(response.paging.next){
link = response.paging.next;
getShare(link,id_post);
}
else{
activeAjaxConnections[id_post]--;
if(activeAjaxConnections[id_post]==0){
getResult(id_post);
}
}
}
else{
activeAjaxConnections[id_post]--;
if(activeAjaxConnections[id_post]==0){
getResult(id_post);
}
}
})
.fail(function() {
getShare(link,id_post);
// alert("Bạn đã nhập 1 cái gì đó sai sai");
});
}
function getLike(id_post){
link = `https://graph.facebook.com/${id_post}/reactions?limit=1&fields=id&summary=true&access_token=${token}`;
$.ajax({
url: link,
dataType: 'json',
})
.success(function(response) {
if(response.summary){
array_like[id_post] = response.summary.total_count;
}
activeAjaxConnections[id_post]--;
if(activeAjaxConnections[id_post]==0){
getResult(id_post);
}
})
.fail(function() {
getLike(id_post);
// alert("Bạn đã nhập 1 cái gì đó sai sai");
});
}
function getComment(id_post){
link = `https://graph.facebook.com/${id_post}?fields=comments&summary=true&access_token=${token}`;
$.ajax({
url: link,
dataType: 'json',
})
.success(function(response) {
if(response.comments){
array_comment[id_post] = response.comments.count;
}
activeAjaxConnections[id_post]--;
if(activeAjaxConnections[id_post]==0){
getResult(id_post);
}
})
}
function getResult(id_post){
array_unique = array_share[id_post].unique();
index = array_index[id_post];
t.row.add( [
index,
`<a href="https://fb.com/${id_post}" target="_blank">fb.com/${id_post}</a>`,
array_like[id_post],
array_comment[id_post],
array_unique.length
] ).draw( true );
}
</script>
</body>
</html>