Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save joshbuchea/c44feb00f994b950048a6ed0fe55a60d to your computer and use it in GitHub Desktop.
Save joshbuchea/c44feb00f994b950048a6ed0fe55a60d to your computer and use it in GitHub Desktop.
Unfollow everyone on Linkedin
(() => {
let count = 0;
function getAllButtons() {
return document.querySelectorAll('button.is-following') || [];
}
async function unfollowAll() {
const buttons = getAllButtons();
for (let button of buttons) {
count = count + 1;
const name = button.parentElement.querySelector(
'.follows-recommendation-card__name',
).innerText;
console.log(`Unfollow #${count}:`, name);
window.scrollTo(0, button.offsetTop - 260);
button.click();
await new Promise((resolve) => setTimeout(resolve, 100));
}
}
async function run() {
await unfollowAll();
window.scrollTo(0, document.body.scrollHeight);
await new Promise((resolve) => setTimeout(resolve, 1000));
const buttons = getAllButtons();
if (buttons.length) run();
}
run();
})();
@thelebdev
Copy link

I would suggest changing the declaration of const name at line 14. Assuming the getAllButtons() function returns 500 buttons, your for loop is going to iterate 500 times.

Each one of these iterations is going to allocate a memory location for name, since at every iteration you're declaring const name.

I propose adding let button; outside of the scope of the for loop, and at every iteration, the code would simply replace the current value of button with the new call to querySelector

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment