Skip to content

Instantly share code, notes, and snippets.

@karnpapon
Last active August 14, 2020 17:32
Show Gist options
  • Save karnpapon/bd2610fdb823c5ade3009ed7c4ecadc3 to your computer and use it in GitHub Desktop.
Save karnpapon/bd2610fdb823c5ade3009ed7c4ecadc3 to your computer and use it in GitHub Desktop.
unfollow page/group/people from facebook's account automatically. simply run in javascript console.
// 1.--------------------declaration--------------------------
// add pages/group/people to unfollow here.
const targetList = {
"page_name_xxx" : "https://www.facebook.com/page_name_to_be_unfollow/",
"group_name_xxx" : "https://www.facebook.com/group/group_name_url_to_be_unfollowed",
"people_name_xxx" : "https://www.facebook.com/name_to_be_unfollow",
}
let offset = 0
// ----------------------------------------------------------
// 2.---------------go to Unfollowed page (Modal).-------------
function goToUnfollowModal(cb){
let account_setting_btn = document.querySelectorAll('div[aria-label="Account"]');
account_setting_btn[0].click()
let level = ['Settings & Privacy', 'News Feed Preferences', 'Unfollow' ]
let i = 0;
function task(level, global_idx) {
setTimeout(function() {
let nodelist = document.querySelectorAll('div[data-visualcompletion="ignore-dynamic"]')
Array.prototype.forEach.call(nodelist, function(value, index) {
let string = level[global_idx]
let match = new RegExp(string, 'g')
if (match.test(value.innerText)){
value.children[0].click()
}
});
}, 3000 * global_idx)
}
while (i < level.length) {
task(level, i);
i++;
}
if(i == level.length){
setTimeout(function() {
cb()
}, 2000 * level.length )
}
}
// ----------------------------------------------------------
// 3.---------------------unfollowing--------------------------
function unfollowing(){
function unfollow(unfollow_target, unfollow_btn){
for(let idx = offset;idx<unfollow_target.length;idx++) {
Object.keys(targetList).map( target => {
let _remove_trailing_slash = targetList[target].replace(/\/$/, "");
let _target = new RegExp(_remove_trailing_slash,'g')
if(_target.test(unfollow_target[idx].href)){
unfollow_btn[idx].click()
console.log('unfollowed = ', target)
}
})
}
offset = unfollow_target.length
}
function scrolling(parent){
parent.scrollTo(0,999999)
}
window.scrollInterval = setInterval(function(element){
let unfollow_target = document.querySelectorAll('a[aria-label="Profile Picture and Profile Page Link"]');
let unfollow_btn = document.querySelectorAll('div[aria-label="Toggle to follow"]');
let parent = unfollow_target[0].parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentNode.parentElement
scrolling(parent)
unfollow(unfollow_target, unfollow_btn)
}, 4000)
}
// ----------------------------------------------------------
// 4.------------------run function--------------------------
goToUnfollowModal(unfollowing)
// clearInterval(window.scrollInterval)
// ----------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment