Skip to content

Instantly share code, notes, and snippets.

@solimanware
Created December 20, 2021 07:29
Show Gist options
  • Save solimanware/bdcbb96f096c67cb325a4b1d82dc0af8 to your computer and use it in GitHub Desktop.
Save solimanware/bdcbb96f096c67cb325a4b1d82dc0af8 to your computer and use it in GitHub Desktop.
const wait = (ms) => new Promise((r) => setTimeout(r, ms));
let count = 0;
async function addFriends() {
const boxes = document.querySelectorAll(
"div.rq0escxv.j83agx80.rj1gh0hx.cbu4d94t.buofh1pr.g5gj957u.ph5uu5jm.b3onmgus.e5nlhep0.ecm0bbzt.n1dktuyu"
);
for (let box of Array.from(boxes)) {
let mutualFriendsText = box.querySelector(".a8c37x1j .ni8dbmo4 .stjgntxs");
let numberOfMutualFiends = Number(
mutualFriendsText?.innerText?.split(" ")[0]
);
if (numberOfMutualFiends > 15) {
let addButton = box.querySelector('div[aria-label="Add Friend"]');
if (
addButton?.innerText == "Add Friend" ||
addButton?.innerText == "Add friend"
) {
await wait(1000);
count++;
console.log("Number of added friends", count);
addButton.click();
await wait(1000);
}
} else {
window.scrollBy(0, 200);
}
}
}
addFriends();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment