Skip to content

Instantly share code, notes, and snippets.

@xmannv
Created February 29, 2020 08:58
Show Gist options
  • Select an option

  • Save xmannv/5c21d8ced8d0ab19c7b0282fb0207f42 to your computer and use it in GitHub Desktop.

Select an option

Save xmannv/5c21d8ced8d0ab19c7b0282fb0207f42 to your computer and use it in GitHub Desktop.
const UnFollowAmount = async () => {
function getCookie(name) {
var value = "; " + document.cookie;
var parts = value.split("; " + name + "=");
if (parts.length == 2) return parts.pop().split(";").shift();
}
// 40 friends a seconds
let amount = 60; // 80/2 = 40
// wait for 5s to next unfollow
let waitTime = 5000;
// Lấy token
const fbDtsg = document.querySelector('input[name=fb_dtsg]').value;
// ID người dùng
const userID = getCookie('c_user');
const selectors = document.querySelectorAll('#timeline-medley .uiList li._698 a');
let i;
for (i = 0; i < amount; i++) {
if (!selectors[i].hasAttribute('data-hovercard')) {
// Xóa profile ko còn sử dụng nhưng vẫn hiển thị trong phần kết bạn
selectors[i].closest('li._698').remove();
continue;
}
const matches = selectors[i].getAttribute('data-hovercard').match(/\d+/);
// ID người bị unfollow
const profileID = matches[0];
console.info(`${i}: unfollowing ${profileID} ...`);
selectors[i].insertAdjacentHTML('afterend', 'working...<br/>');
fetch("https://www.facebook.com/ajax/follow/unfollow_profile.php", {
"credentials": "include",
"headers": {
"accept": "*/*",
"accept-language": "en-US,en;q=0.9,vi;q=0.8,lb;q=0.7",
"content-type": "application/x-www-form-urlencoded",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
},
"referrer": "https://www.facebook.com/",
"referrerPolicy": "origin-when-cross-origin",
"body": `profile_id=${profileID}&location=5&__user=${userID}&__a=1&fb_dtsg=${fbDtsg}`,
"method": "POST",
"mode": "cors"
}).then((response) => {
// scroll để force facebook load thêm list friend
// Xóa friend dom để dành chỗ cho liệt check sau
selectors[i].closest('li._698').remove();
console.warn(`unfollowed ${profileID} ...`);
});
}
window.scrollTo(0, 2500);
// Tiếp tục check sau 2s đợi load thêm danh sách
const checkInterval = setInterval(() => {
const selectors = document.querySelectorAll('#timeline-medley .uiList li._698 a');
if (selectors.length < amount) {
console.info('waiting for new friends');
return;
}
clearInterval(checkInterval);
UnFollowAmount();
/*
setTimeout(() => {
UnFollowAmount();
}, waitTime * 1000)
*/
}, waitTime);
};
UnFollowAmount();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment