Created
December 15, 2025 21:03
-
-
Save teyfix/c7d9828a91b03298a616b518a760c6de to your computer and use it in GitHub Desktop.
Unfollow LinkedIn connections
This file contains hidden or 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
| (async function unfolowLinkedin() { | |
| /** | |
| * Sleep for a given duration | |
| * | |
| * @param {number} ms Duration to sleep in ms | |
| * @returns {Promise<void>} A promise that resolves when the sleep is over | |
| */ | |
| const sleep = async (ms) => { | |
| console.info("Sleeping for %dms", ms); | |
| return new Promise((resolve) => setTimeout(resolve, ms)); | |
| }; | |
| /** | |
| * Get a random number between min and max | |
| * | |
| * @param {number} min Minimum number | |
| * @param {number} max Maximum number | |
| * @returns {number} Random number | |
| */ | |
| const random = (min, max) => | |
| Math.floor(Math.random() * (max - min + 1)) + min; | |
| /** | |
| * Button text pattern for unfollow or pagination | |
| * | |
| * @type {RegExp} | |
| */ | |
| const pattern = /following|unfollow|show more results/i; | |
| /** | |
| * Checks if a button is a pagination button | |
| * | |
| * @param {HTMLButtonElement} button | |
| * @returns | |
| */ | |
| const isPagination = (button) => /show more results/i.test(button.innerText); | |
| /** | |
| * | |
| * Returns a list of buttons to click for unfollowing | |
| * and pagination | |
| * | |
| * @returns {HTMLButtonElement[]} Buttons to click | |
| */ | |
| const getClickButtons = () => { | |
| return [...document.querySelectorAll("button:not([disabled])")] | |
| .filter((button) => pattern.test(button.innerText)) | |
| .sort((a, b) => isPagination(a) - isPagination(b)) | |
| .slice(0, 3); | |
| }; | |
| /** | |
| * List of buttons to click | |
| */ | |
| let buttons = getClickButtons(); | |
| if (!buttons.length) { | |
| console.info("No unfollow buttons found"); | |
| return; | |
| } | |
| for (const unfollow of buttons) { | |
| try { | |
| if (/following|unfollow/i.test(unfollow.innerText)) { | |
| unfollow.scrollIntoView({ behavior: "instant" }); | |
| unfollow.click(); | |
| } | |
| } catch (err) { | |
| console.info("Could not click: %s", err); | |
| } | |
| await sleep(random(200, 350)); | |
| buttons = getClickButtons(); | |
| } | |
| await unfolowLinkedin(); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment