Created
April 8, 2023 07:57
-
-
Save tahafarooqui/764fe05a9c8dea9ec4a0a69c16ec4814 to your computer and use it in GitHub Desktop.
LinkedIn Unfollow Following Connections Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(() => { | |
let count = 0; | |
function getAllButtons() { | |
return document.querySelectorAll('button[data-control-name="entity_action_primary"]') || []; | |
} | |
async function unfollowAll() { | |
const buttons = getAllButtons(); | |
for (let button of buttons) { | |
count = count + 1; | |
const name = button.parentElement.querySelector( | |
'.follows-recommendation-card__name', | |
)?.innerText || 'Unknown'; | |
console.log(`Unfollow #${count}:`, name); | |
window.scrollTo(0, button.offsetTop - 260); | |
button.click(); | |
// Wait for the Unfollow confirmation dialog to appear | |
await new Promise((resolve) => setTimeout(resolve, 500)); | |
// Click the Unfollow confirmation button | |
const confirmButton = document.querySelector('.artdeco-modal__confirm-dialog-btn.artdeco-button.artdeco-button--2.artdeco-button--primary.ember-view'); | |
if (confirmButton) confirmButton.click(); | |
// Wait for 5 seconds (5000 ms) before unfollowing the next connection | |
await new Promise((resolve) => setTimeout(resolve, 5000)); | |
} | |
} | |
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(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment