-
-
Notifications
You must be signed in to change notification settings - Fork 226
/
Copy pathcount_reaction_friend.html
759 lines (379 loc) · 15.1 KB
/
count_reaction_friend.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"> <title>Lọc Bạn Bè Không Tương Tác</title>
<!-- Latest compiled and minified CSS & JS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.15/css/dataTables.bootstrap.min.css">
<script src="//code.jquery.com/jquery.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script src="https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.15/js/dataTables.bootstrap.min.js"></script>
<style type="text/css">
body {
background: #3332;
}
.container{
margin-top: 15px;
}
.button-action{
text-align: center;
}
.container > .row > .table tr.active th,
.container > .row > .table tr.active td {
background-color:#123456;
color: white;
font-weight: bold;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<center><h2 style="color: blue;">TOOLS LỌC BẠN BÈ TƯƠNG TÁC</h2></center>
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Lọc danh sách bạn bè không tương tác</h3>
</div>
<div class="panel-body">
<div class="col-md-12">
<div class="form-group">
<input type="text" name="" id="accessToken" class="form-control" value="" required="required" placeholder="Nhập Mã Access Token Full Quyền">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Chọn Giới Tính</label>
<select name="" id="gender" class="form-control" required="required" title="Giới Tính Bạn Bè Muốn Lọc">
<option value="all">Tất Cả</option>
<option value="male">Nam</option>
<option value="female">Nữ</option>
<option value="500fr">Bạn Bè Dưới 500</option>
<option value="vn">Bạn Bè Là Người Nước Ngoài</option>
</select>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Chọn Số Lượng Post</label>
<select name="" id="total_post" class="form-control" required="required" title="Lượng Post Muốn Quét">
<option value="10">10</option>
<option value="20">20</option>
<option value="50">50</option>
<option value="50">100</option>
<option value="200">200</option>
<option value="10000">10000</option>
</select>
</div>
</div>
<div class="col-md-12">
<div class="form-group button-action">
<button type="button" class="btn btn-success" onclick="getListFriend();">Tiến Hành Lọc</button>
<button type="button" class="btn btn-danger" onclick="Del_0_Point();">Xóa Bạn Có Điểm Tương Tác Bằng 0</button>
<button type="button" class="btn btn-danger" onclick="Del_Selected();">Xóa Bạn Đã Chọn</button>
</div>
</div>
<div class="col-md-12">
<div class="alert alert-info" id="result-msg" style="display: none;">
</div>
</div>
</div>
</div>
<div class="panel panel-primary" style="display: none;" id="ds-friends">
<div class="panel-heading">
<h3 class="panel-title">Danh Sách Xếp Hạng</h3>
</div>
<div class="panel-body">
<div class="table-responsive">
<table class="table table-bordered" width="100%" id="table-friends">
</table>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
var _Friends = new Array();
var _Comments = new Array();
var _Reactions = new Array();
$("#table-friends").on('click', 'tr', function() {
$(this).toggleClass('active');
});
function getListFriend() {
_TOKEN = $("#accessToken").val();
if (!_TOKEN) {
alert("Vui Lòng Nhập Mã Access Token Full Quyền!");
return false;
}
$("#result-msg").html('<img src="https://www.drupal.org/files/issues/throbber_13.gif" width="30" height="30" /> Đang Lấy Thông Tin. Vui Lòng Đợi...').fadeIn("slow");
var gender = $("#gender").val();
if (gender == 'male') {
var a = 'AND sex != \'female\'';
var a = 'SELECT friend_count, uid, name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND sex != "female" ORDER BY rand() LIMIT 5000';
} else if (gender == "female") {
var a = 'SELECT friend_count, uid, name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND sex != "male" ORDER BY rand() LIMIT 5000';
} else if (gender == 'die'){
var a = 'SELECT id, name FROM profile WHERE id IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND name = "Facebook User" ORDER BY rand() LIMIT 5000';
} else if(gender == '500fr'){
var a = 'SELECT friend_count, uid, name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND friend_count < 500 ORDER BY rand() LIMIT 5000';
} else if(gender == 'vn'){
var a = 'SELECT locale, uid, name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND locale != "vi_VN" ORDER BY rand() LIMIT 5000';
} else if(gender == 'vn'){
var a = 'SELECT locale, uid, name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND locale != "vi_VN" ORDER BY rand() LIMIT 5000';
} else {
var a = 'SELECT uid, name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) ORDER BY rand() LIMIT 5000';
}
$.ajax({
url: "https://graph.facebook.com/fql",
type: "GET",
dataType: "JSON",
data: {
access_token: _TOKEN,
q: a
},
success: (data) => {
_Friends = data.data;
getStatus();
}
})
}
function showFriends(Data) {
var arrFriends = new Array();
$.each(Data, (i, item) => {
arrFriends[i] = [
(i + 1),
'<img src="https://graph.facebook.com/' + item.uid + '/picture?width=30&height=30" /> <a target="_blank" href="https://fb.com/' + item.uid + '"> ' + item.name + '</a>',
item.uid,
item.reaction,
item.comment,
(item.comment * 2 + item.reaction) * 100
];
})
$('#table-friends').DataTable({
destroy: true,
data: arrFriends,
columns: [{
title: "STT"
},
{
title: "FB NAME"
},
{
title: "FB ID"
},
{
title: "REACT"
},
{
title: "COMMENT"
},
{
title: "POINT"
},
],
"order": [
[5, "desc"]
],
"language": {
"search": "Tìm Kiếm",
"paginate": {
"first": "Về Đầu",
"last": "Về Cuối",
"next": "Tiến",
"previous": "Lùi"
},
"info": "Hiển thị _START_ đến _END_ của _TOTAL_ mục",
"infoEmpty": "Hiển thị 0 đến 0 của 0 mục",
"lengthMenu": "Hiển thị _MENU_ mục",
"loadingRecords": "Đang tải...",
"emptyTable": "Không có gì để hiển thị",
}
});
}
function getStatus() {
$("#result-msg").empty().html('<img src="https://www.drupal.org/files/issues/throbber_13.gif" width="30" height="30" /> Đang Lấy Thông Tin Tương Tác...');
var limit = $("#total_post").val();
$.ajax({
url: "https://graph.facebook.com/me/feed",
type: "GET",
dataType: "JSON",
data: {
limit: limit,
access_token: _TOKEN,
fields: "id"
},
success: (data) => {
getComments(data.data);
getReactions(data.data);
setTimeout((e) => {
Ranking();
}, 10000)
}
})
}
function getReactions(Status) {
var limit = 10000;
for (var i = 0; i < Status.length; i++) {
$.ajax({
url: "https://graph.facebook.com/" + Status[i].id + "/",
type: "GET",
dataType: "JSON",
data: {
access_token: _TOKEN,
fields: "reactions.limit(" + limit + ").summary(true)"
},
success: (data) => {
if (data.reactions.data) {
exPortReactions(data.reactions.data)
}
}
})
}
}
function exPortReactions(Reactions) {
for (var i = 0; i < Reactions.length; i++) {
_Reactions.push(parseInt(Reactions[i].id));
}
}
function getComments(Status) {
var limit = 1000;
for (var i = 0; i < Status.length; i++) {
$.ajax({
url: "https://graph.facebook.com/" + Status[i].id + "/",
type: "GET",
dataType: "JSON",
data: {
access_token: _TOKEN,
fields: "comments.limit(" + limit + ").summary(true)"
},
success: (data) => {
if (data.comments.data) {
getComments2(data.comments.data);
}
}
})
}
}
function getComments2(Comments) {
var limit = 2000
for (var i = 0; i < Comments.length; i++) {
_Comments.push(parseInt(Comments[i].from.id));
$.ajax({
url: "https://graph.facebook.com/" + Comments[i].id + "/",
type: "GET",
dataType: "JSON",
data: {
access_token: _TOKEN,
fields: "comments.limit(" + limit + ").summary(true)"
},
success: (data) => {
if (data.comments) {
exPortComments(data.comments.data);
}
}
})
}
}
function exPortComments(Comments) {
for (var i = 0; i < Comments.length; i++) {
_Comments.push(parseInt(Comments[i].from.id));
}
}
function Ranking() {
$("#result-msg").empty().html('<img src="https://www.drupal.org/files/issues/throbber_13.gif" width="30" height="30" /> Đang Tính Toán Thứ Hạng ...');
for (var i = 0; i < _Friends.length; i++) {
_Friends[i].reaction = countItems(_Reactions, _Friends[i].uid);
_Friends[i].comment = countItems(_Comments, _Friends[i].uid);
}
$("#ds-friends").fadeIn("slow");
setTimeout((e) => {
$("#result-msg").empty().html('<img src="http://uxotucung.org/wp-content/uploads/2016/03/tick-1-500x500.png" width="30" height="30" /> Thành Công!');
show();
}, 5000)
}
function show() {
showFriends(_Friends);
}
function arrayCountValues(arr) {
var v, freqs = {};
for (var i = arr.length; i--;) {
v = arr[i];
if (freqs[v]) freqs[v] += 1;
else freqs[v] = 1;
}
return freqs;
}
function countItems(arr, what) {
var count = 0,
i;
while ((i = arr.indexOf(what, i)) != -1) {
++count;
++i;
}
return count;
}
$("Del_0_Point").html('<img src="https://www.drupal.org/files/issues/throbber_13.gif" width="30" height="30" /> Đang Lấy Thông Tin. Vui Lòng Đợi...').fadeIn("slow");
function Del_0_Point() {
$.each(_Friends, (i, item) => {
if ((item.reaction + item.comment) === 0) {
removeFriend(i, item);
}
})
}
function Del_Selected() {
var Data = $("#table-friends").DataTable().rows('.active').data();
for (var i = 0; i < Data.length; i++) {
removeFriend2(i, Data[i][2], Data[i][1].match(/"> (.*)</)[1]);
}
}
function removeFriend2(i, FBID, NAME) {
! function(i, FBID, NAME) {
setTimeout(function() {
$.ajax({
url: 'https://graph.facebook.com/me/friends/' + FBID,
type: "GET",
dataType: "JSON",
data: {
access_token: _TOKEN,
method: "delete",
}
}).done((e) => {
$("#result-msg").fadeOut("slow", function() {
$("#result-msg").empty().html('<img src="https://www.ochealthiertogether.org/content/global/application/indicators/gauges/target-met.png" width="20" height="20" /> Đã Xóa: <img src="https://graph.facebook.com/' + FBID + '/picture?width=30&height=30" /> ' + NAME + '(' + FBID + ')').fadeIn("slow");
})
}).error((e) => {
$("#result-msg").fadeOut("slow", function() {
$("#result-msg").empty().html('<img src="https://cdn.pixabay.com/photo/2017/02/12/21/29/false-2061132_960_720.png" width="20" height="20" /> Đã Xóa: <img src="https://graph.facebook.com/' + FBID + '/picture?width=30&height=30" /> ' + NAME + '(' + FBID + ')').fadeIn("slow");
})
})
}, i * 500)
}
(i, FBID, NAME)
}
function removeFriend(i, USER) {
! function(i, USER) {
setTimeout(function() {
$.ajax({
url: 'https://graph.facebook.com/me/friends/' + USER.uid,
type: "GET",
dataType: "JSON",
data: {
access_token: _TOKEN,
method: "delete",
}
}).done((e) => {
$("#result-msg").fadeOut("slow", function() {
$("#result-msg").empty().html('<img src="https://www.ochealthiertogether.org/content/global/application/indicators/gauges/target-met.png" width="20" height="20" /> Đã Xóa: <img src="https://graph.facebook.com/' + item.uid + '/picture?width=30&height=30" /> ' + USER.name + '(' + USER.uid + ')').fadeIn("slow");
})
}).error((e) => {
$("#result-msg").fadeOut("slow", function() {
$("#result-msg").empty().html('<img src="https://cdn.pixabay.com/photo/2017/02/12/21/29/false-2061132_960_720.png" width="20" height="20" /> Đã Xóa: <img src="https://graph.facebook.com/' + item.uid + '/picture?width=30&height=30" /> ' + USER.name + '(' + USER.uid + ')').fadeIn("slow");
})
})
}, i * 300)
}
(i, USER)
}
</script>
</body>
</html>