Skip to content

Instantly share code, notes, and snippets.

@bertolo1988
Last active January 1, 2024 20:23
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 12 You must be signed in to fork a gist
  • Save bertolo1988/9d285c4ac2b2c10c6026d74a671da9f9 to your computer and use it in GitHub Desktop.
Save bertolo1988/9d285c4ac2b2c10c6026d74a671da9f9 to your computer and use it in GitHub Desktop.
Quickly your LinkedIn network
// 1. load https://www.linkedin.com/mynetwork/
// 2. make sure your LinkedIn is in English
// 3. paste this script on chrome dev tools at your own risk
async function moreConnectionsPlease() {
// maximum limit of Connect buttons clicked
const LIMIT = 500;
// wait in ms before each scroll
const SCROLL_TIMEOUT = 600;
// bulk scroll will scroll this amount of times
const BULK_SCROLL_COUNT = 15;
// wait in ms before each click
const CLICK_DELAY = 300;
// if this amount of connections in the page, time to click
const MINIMUM_CONNECTS_TO_CLICK = 60;
// if this amount of connections in the page, time to scroll
const MINIMUM_CONNECTS_TO_SCROLL = 10;
var connects = 0;
var fails = 0;
// retrieves array "Connect" buttons
function selectButtonElements() {
return [...document.querySelectorAll("button span")].filter(a =>
a.textContent.includes("Connect")
);
}
// scrolls to the bottom of the page
async function singleScroll() {
return new Promise(resolve => {
setTimeout(() => {
window.scrollTo(0, document.body.scrollHeight);
console.log("scroll!");
resolve();
}, SCROLL_TIMEOUT);
});
}
// delays an html element click
async function singleClick(elem) {
return new Promise(resolve => {
setTimeout(() => {
elem.click();
resolve();
}, CLICK_DELAY);
});
}
// scroll to the bottom of the page several times
async function bulkScroll() {
for (let i = 0; i < BULK_SCROLL_COUNT; i++) {
await singleScroll();
}
}
// click on all but a few Connect buttons
async function bulkClick() {
let elements = selectButtonElements();
console.log("elements length:", elements.length);
for (let i = 0; i < elements.length - MINIMUM_CONNECTS_TO_SCROLL; i++) {
try {
await singleClick(elements[i]);
console.log("click!");
connects++;
} catch (err) {
fails++;
}
}
}
// the list of people to connect to must keep a minimum amount of people
function isManyConnects(amount) {
return selectButtonElements().length >= amount;
}
do {
if (isManyConnects(MINIMUM_CONNECTS_TO_CLICK)) {
console.log("There are plenty of connections, time to click...");
await bulkClick();
} else {
console.log("Out of connections, need to scroll...");
await bulkScroll();
}
console.log(`New Connections:${connects} Failed clicks:${fails}`);
} while (connects < LIMIT);
}
moreConnectionsPlease();
@langladed
Copy link

super thanks, Is there possible to make the invitation only for people who have in their description "CEO" ?

@mariiio
Copy link

mariiio commented Apr 20, 2020

super thanks, Is there possible to make the invitation only for people who have in their description "CEO" ?

Hey @langladed, check out LinkedIn Connect. It's meant to work in companies employees page rather than your personal network page but has the feature you're looking for.

If you want to adapt it to this code somthing like this should do the trick:

+  // keywords to filter employees in specific positions
+  const POSITION_KEYWORDS = ["ceo"];
   // retrieves array "Connect" buttons
   function selectButtonElements() {
-    return [...document.querySelectorAll("button span")].filter(a =>
+    return [...document.querySelectorAll("button span")].filter(a => {
+      let cardInfo = a.offsetParent.innerText.split("\n");
+      let roleIndex = cardInfo.length > 3 ? 3 : 1;
+      let role = cardInfo[roleIndex];
+       return (
-        a.textContent.includes("Connect")
+        a.textContent.includes("Connect") &&
+        POSITION_KEYWORDS.some((r) => role.match(new RegExp(r, "gi")))
       );
+    });
   }

@delphi20
Copy link

is there a way to send connection requests to people in a specific area ?

@mohit0121
Copy link

I am new to programming, I dont know how to include the above code stated by you for the ceo description, would it be possible for you to put it as a single code and share with us ?

@Kaminel24
Copy link

Where do I insert the job title code?

Thank you in advance!

Kami

@gaelgerard
Copy link

Bonjour,

the script seems to scroll but not to click. Is it still working ?

I keep getting this message in console logs :

New Connections:0 Failed clicks:0

Merci

@0xankit
Copy link

0xankit commented Dec 14, 2023

It first scrolls BULK_SCROLL_COUNT times then starts clicking

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