Skip to content

Instantly share code, notes, and snippets.

@egoing
Last active May 20, 2017 15:20
Show Gist options
  • Save egoing/1f14bbe0cba467ccacfb to your computer and use it in GitHub Desktop.
Save egoing/1f14bbe0cba467ccacfb to your computer and use it in GitHub Desktop.
페이스북 자동 가입
auto_register = new Object();
auto_register.add_member = function(member_id, group_id, ignore, callback) {
x = new XMLHttpRequest();
x.onreadystatechange = function() {
if (x.readyState == 4) {
if (x.status == 200) {
if (callback)
callback(member_id, group_id);
console.log('success', member_id);
} else
console.log('error member_id => ', member_id)
}
};
x.open('POST', '/ajax/groups/members/add_post.php', false);
x.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
param = [];
if (ignore) {
param.push('ignore=1');
}
param.push('group_id=' + group_id);
param.push('members%5B0%5D=' + member_id);
param.push('source=requests_queue');
param.push('nctr[_mod]=pagelet_requests_queu');
param.push('fb_dtsg=' + document.querySelector('[name=fb_dtsg]').value);
x.send(param.join('&'));
}
auto_register.fb_group_check_member = function(callback) {
var lis = document.querySelectorAll('#pagelet_requests_queue .uiList._4kg._6-h._6-j._4ks>li');
var result_table = [];
for (var i = 0; i < lis.length; i++) {
var info = {}
var t = lis[i];
var n = t.querySelector('.fsm.fwn.fcg a');
if (n == null) {
info = false;
} else {
info.name = n.innerText;
}
var mts = t.querySelector('.mts');
info.since = (Date.now()/1000 - mts.querySelector('abbr').getAttribute('data-utime'))/60/60/24;
var belong = mts.firstChild.nextSibling.innerText;
var _rel = mts.querySelectorAll('.fsm.fwn.fcg');
if (_rel != null) {
var r1 = _rel[0] ? _rel[0].innerText : '그룹 내 친구 0명';
var r2 = _rel[1] ? _rel[1].innerText : '함께 아는 친구 0명';
} else {
var r1 = '그룹 내 친구 0명';
var r2 = '함께 아는 친구 0명';
}
var _rb = /.+ ([0-9]+).+/;
_r = belong.match(_rb);
if(!_r){
if(belong.indexOf(',') > -1 || belong !== '') {
info.belong = belong.split(',').length;
} else {
info.belong = 0;
}
} else {
info.belong = _r[1];
}
info.inFriend = r1.match(_rb)[1];
info.withFriend = r2.match(_rb)[1];
var kor_check = /([^가-힣ㄱ-ㅎㅏ-ㅣ\x20])/i;
info.isKorean = !kor_check.test(info.name);
var result = callback(info);
var approval_btn = t.querySelectorAll('._51xa.rfloat._ohf a._4jy1')[0];
var denines = t.querySelectorAll('._42ft._4jy0._4jy3._517h._51sy');
var matchs = approval_btn.getAttribute('ajaxify').match(/group_id=([0-9]+).+(members%5B0%5D=(.+?)\&)/);
var group_id = matchs[1];
var member_id = matchs[3];
for (var j = 0; j < denines.length; j++) {
if (denines[j].getAttribute('ajaxify').indexOf('&block_user') > -1) {
var block_btn = denines[j];
} else {
var ignore_btn = denines[j];
}
}
t.style.border = '1px solid gray';
if (result === -1 || result === 0) {
info.result = '무시';
t.style.backgroundColor = 'red';
t.style.color = 'white';
// this.add_member(member_id, group_id, true, function(member_id, group_id) {
// console.log('ignored member_id:' + member_id, Math.ceil(i / lis.length*100)+'%');
// });
} else if (result === 1) {
info.result = '승인';
this.add_member(member_id, group_id, false, function(member_id, group_id) {
console.log('accepted member_id:' + member_id, Math.ceil(i / lis.length*100)+'%');
});
t.style.opacity = 0.3;
} else if (result === false) {
info.result = '처리안함';
t.style.backgroundColor = 'powderblue';
}
result_table.push(info);
}
console.table(result_table);
}
auto_register.fb_group_check_member(function(info) {
// 1 : 승인, 0 : 무시, -1 : 차단
if (info === false) {
return 0;
}
if (info.belong > 500) {
return 0;
}
if (info.isKorean) {
if (info.since > 365) {
return 1;
}
if (info.inFriend > 3) {
return 1;
}
if (info.withFriend > 2) {
return 1;
}
}
if (info.since > 365) {
if (info.belong < 5) {
return 1;
}
}
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment