Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
JS script to send connection requests to your LinkedIn search results with customisation options, accept all received connection requests, and withdraw pending sent connection requests.
// If the script does not work, you may need to allow same site scripting https://stackoverflow.com/a/50902950
Linkedin = {
config: {
scrollDelay: 3000,
actionDelay: 5000,
nextPageDelay: 5000,
// set to -1 for no limit
maxRequests: -1,
totalRequestsSent: 0,
// set to false to skip adding note in invites
addNote: true,
note: "Hey {{name}}, I'm looking forward to connecting with you!"
},
init: function (data, config) {
console.info("INFO: script initialized on the page...");
console.debug("DEBUG: scrolling to bottom in " + config.scrollDelay + " ms");
setTimeout(() => this.scrollBottom(data, config), config.actionDelay);
},
scrollBottom: function (data, config) {
window.scrollTo({ top: document.body.scrollHeight, behavior: 'smooth' });
console.debug("DEBUG: scrolling to top in " + config.scrollDelay + " ms");
setTimeout(() => this.scrollTop(data, config), config.scrollDelay);
},
scrollTop: function (data, config){
window.scrollTo({ top: 0, behavior: 'smooth' });
console.debug("DEBUG: inspecting elements in " + config.scrollDelay + " ms");
setTimeout(() => this.inspect(data, config), config.scrollDelay);
},
inspect: function (data, config) {
var totalRows = this.totalRows();
console.debug("DEBUG: total search results found on page are " + totalRows);
if (totalRows >= 0) {
this.compile(data, config);
} else {
console.warn("WARN: end of search results!");
this.complete(config);
}
},
compile: function (data, config) {
var elements = document.querySelectorAll('button');
data.pageButtons = [...elements].filter(function (element) {
return element.textContent.trim() === "Connect";
});
if (!data.pageButtons || data.pageButtons.length === 0) {
console.warn("ERROR: no connect buttons found on page!");
console.info("INFO: moving to next page...");
setTimeout(() => { this.nextPage(config) }, config.nextPageDelay);
} else {
data.pageButtonTotal = data.pageButtons.length;
console.info("INFO: " + data.pageButtonTotal + " connect buttons found");
data.pageButtonIndex = 0;
var names = document.getElementsByClassName("entity-result__title-text");
names = [...names].filter(function (element) {
return element.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.textContent.includes("Connect\n");
});
data.connectNames = [...names].map(function (element) {
return element.innerText.split(" ")[0];
});
console.debug("DEBUG: starting to send invites in " + config.actionDelay + " ms");
setTimeout(() => { this.sendInvites(data, config) }, config.actionDelay);
}
},
sendInvites: function (data, config) {
console.debug("remaining requests " + config.maxRequests);
if (config.maxRequests == 0){
console.info("INFO: max requests reached for the script run!");
this.complete(config);
} else {
console.debug('DEBUG: sending invite to ' + (data.pageButtonIndex + 1) + ' out of ' + data.pageButtonTotal);
var button = data.pageButtons[data.pageButtonIndex];
button.click();
if (config.addNote && config.note) {
console.debug("DEBUG: clicking Add a note in popup, if present, in " + config.actionDelay + " ms");
setTimeout(() => this.clickAddNote(data, config), config.actionDelay);
} else {
console.debug("DEBUG: clicking done in popup, if present, in " + config.actionDelay + " ms");
setTimeout(() => this.clickDone(data, config), config.actionDelay);
}
}
},
clickAddNote: function (data, config) {
var buttons = document.querySelectorAll('button');
var addNoteButton = Array.prototype.filter.call(buttons, function (el) {
return el.textContent.trim() === 'Add a note';
});
// adding note if required
if (addNoteButton && addNoteButton[0]) {
console.debug("DEBUG: clicking add a note button to paste note");
addNoteButton[0].click();
console.debug("DEBUG: pasting note in " + config.actionDelay);
setTimeout(() => this.pasteNote(data, config), config.actionDelay);
} else {
console.debug("DEBUG: add note button not found, clicking send on the popup in " + config.actionDelay);
setTimeout(() => this.clickDone(data, config), config.actionDelay);
}
},
pasteNote: function (data, config) {
noteTextBox = document.getElementById("custom-message");
noteTextBox.value = config.note.replace("{{name}}", data.connectNames[data.pageButtonIndex]);
noteTextBox.dispatchEvent(new Event('input', {
bubbles: true
}));
console.debug("DEBUG: clicking send in popup, if present, in " + config.actionDelay + " ms");
setTimeout(() => this.clickDone(data, config), config.actionDelay);
},
clickDone: function (data, config) {
var buttons = document.querySelectorAll('button');
var doneButton = Array.prototype.filter.call(buttons, function (el) {
return el.textContent.trim() === 'Send';
});
// Click the first send button
if (doneButton && doneButton[0]) {
console.debug("DEBUG: clicking send button to close popup");
doneButton[0].click();
} else {
console.debug("DEBUG: send button not found, clicking close on the popup in " + config.actionDelay);
}
setTimeout(() => this.clickClose(data, config), config.actionDelay);
},
clickClose: function (data, config) {
var closeButton = document.getElementsByClassName('artdeco-modal__dismiss artdeco-button artdeco-button--circle artdeco-button--muted artdeco-button--2 artdeco-button--tertiary ember-view');
if (closeButton && closeButton[0]) {
closeButton[0].click();
}
console.info('INFO: invite sent to ' + (data.pageButtonIndex + 1) + ' out of ' + data.pageButtonTotal);
config.maxRequests--;
config.totalRequestsSent++;
if (data.pageButtonIndex === (data.pageButtonTotal - 1)) {
console.debug("DEBUG: all connections for the page done, going to next page in " + config.actionDelay + " ms");
setTimeout(() => this.nextPage(config), config.actionDelay);
} else {
data.pageButtonIndex++;
console.debug("DEBUG: sending next invite in " + config.actionDelay + " ms");
setTimeout(() => this.sendInvites(data, config), config.actionDelay);
}
},
nextPage: function (config) {
var pagerButton = document.getElementsByClassName('artdeco-pagination__button--next');
if (!pagerButton || pagerButton.length === 0 || pagerButton[0].hasAttribute('disabled')) {
console.info("INFO: no next page button found!");
return this.complete(config);
}
console.info("INFO: Going to next page...");
pagerButton[0].children[0].click();
setTimeout(() => this.init({}, config), config.nextPageDelay);
},
complete: function (config) {
console.info('INFO: script completed after sending ' + config.totalRequestsSent + ' connection requests');
},
totalRows: function () {
var search_results = document.getElementsByClassName('search-result');
if (search_results && search_results.length != 0) {
return search_results.length;
} else {
return 0;
}
}
}
Linkedin.init({}, Linkedin.config);
@thealphadollar
Copy link
Author

thealphadollar commented Jan 27, 2021

Yes. I would be glad to help with the integration!

@ayoola000
Copy link

ayoola000 commented Jan 27, 2021

@thealphadollar
Copy link
Author

thealphadollar commented Jan 27, 2021

It won't be feasible on short notice. Let's connect over email - code@thealphadollar.me

@ayoola000
Copy link

ayoola000 commented Jan 27, 2021

@sherifmawad1
Copy link

sherifmawad1 commented Jan 29, 2021

Hello @thehealphadollar
Great work
Does the script work for messaging 1st degree connections?

@le-pandaman
Copy link

le-pandaman commented Feb 1, 2021

image

Even after sending the messages, here's the look of the connect buttons. It should be grayed out right?

@Zhatabsaifi
Copy link

Zhatabsaifi commented Feb 22, 2021

Why this script send the note message only to few connection not all ?

When first time i used this script this was perfectly run. But now it's not send the note message.
I don't know why?

@ayoola000
Copy link

ayoola000 commented Feb 22, 2021

@thealphadollar
Copy link
Author

thealphadollar commented Feb 23, 2021

Hey @ayoola000 I don't have experience with vue.

@thealphadollar
Copy link
Author

thealphadollar commented Feb 24, 2021

Does the script work for messaging 1st degree connections?

Yeah. @sherifmawad1

Even after sending the messages, here's the look of the connect buttons. It should be grayed out right?

Yes, it should be grayed out. I think it may be a rendering issue in your browser given connection requests were successfully sent. @CharlesDecena

When first time i used this script this was perfectly run. But now it's not send the note message.
I don't know why?

Same here. Even I'm not sure why it would stop working after few requests. Can you please look into the developer console in the browser and see if some logs are there? @Zhatabsaifi

@Zhatabsaifi
Copy link

Zhatabsaifi commented Feb 24, 2021

It stop working when any primum linkedin member come because you can't send request them directly.

No logs come

@karenbrsikyan
Copy link

karenbrsikyan commented Feb 26, 2021

A small fix on line #140
if (!pagerButton || pagerButton.length === 0 || pagerButton[0].hasAttribute('disabled')) {

@Zhatabsaifi
Copy link

Zhatabsaifi commented Feb 28, 2021

noteTextBox.value = config.note.replace("{{name}}", data.connectNames[data.pageButtonIndex]);

why this error come in this line.

VM180:253 Uncaught TypeError: Cannot set property 'value' of null
at Object.pasteNote (:253:27)
at :245:35

@Zhatabsaifi
Copy link

Zhatabsaifi commented Feb 28, 2021

and note message only goes to some people not all in this query.

@thealphadollar
Copy link
Author

thealphadollar commented Mar 2, 2021

@karenbrsikyan Thanks for the fix.

@Scoobysnacks1
Copy link

Scoobysnacks1 commented Mar 2, 2021

Hey all, Just want to say this is absolutely fantastic work! I am very grateful. However, I have encountered a problem. The script generally connects with Page 1 and sometimes Page 2 but generally after that it says that it cannot find the 'Next' button to go on to the next page. Does anyone know why this is? Any help greatly appreciated. James

@ayoola000
Copy link

ayoola000 commented Mar 10, 2021

Do you have any experience with react, I want to add this to a google extension, having problems with type script..

@Damon-Wu
Copy link

Damon-Wu commented Mar 15, 2021

Hey all, Just want to say this is absolutely fantastic work! I am very grateful. However, I have encountered a problem. The script generally connects with Page 1 and sometimes Page 2 but generally after that it says that it cannot find the 'Next' button to go on to the next page. Does anyone know why this is? Any help greatly appreciated. James

Hi Shivam, I meet the same problem. it can not add more after 1sth page. 2nd page can not automatically connnect!!! can you fix it?

@Damon-Wu
Copy link

Damon-Wu commented Mar 15, 2021

@Crewxx
Copy link

Crewxx commented Apr 7, 2021

Hey @thealphadollar, thanks once again for your dedicated time on this script. I haven't used it for a while now and when I used it yesterday, it's still working fine. Thank You

Please a NOTIFICATION: I tested the sent invite withdrawal script and it didn't work, could you maybe find time to check it out.

@thealphadollar
Copy link
Author

thealphadollar commented May 27, 2021

@Crewxx Thanks for notifying me. It was a minor typo and I've fixed it. You can now use the script of withdrawing sent invites.

@thealphadollar
Copy link
Author

thealphadollar commented May 27, 2021

Hi Shivam, I meet the same problem. it can not add more after 1sth page. 2nd page can not automatically connnect!!! can you fix it?

Hey @Damon-Wu , I'm unable to reproduce the error. Can you please screen record and help me understand the issue better?

@Crewxx
Copy link

Crewxx commented May 27, 2021

@Crewxx Thanks for notifying me. It was a minor typo and I've fixed it. You can now use the script of withdrawing sent invites.

Okay great and thanks @thealphadollar

@saroar
Copy link

saroar commented Jan 20, 2022

Screenshot 2022-01-19 at 16 34 58

not working :(

@thealphadollar
Copy link
Author

thealphadollar commented Jan 20, 2022

@saroar Hey! I'd want you to provide more information before we can debug the issue.

@saroar
Copy link

saroar commented Jan 21, 2022

@thealphadollar what information are you like to know when i run this code its working as expected until send button click

  1. its click Connect button fill msg then click send button then i got this error

@Aliss20
Copy link

Aliss20 commented Apr 11, 2022

@saroar
I've found the problem , if you still haven't solved it .
Can you send me the message you' re sending in the variable note.

@Aliss20
Copy link

Aliss20 commented Apr 11, 2022

Otherwise , it can be the problem of Content Security Policy
After checking the first posssibility , visit this website
https://stackoverflow.com/questions/37298608/content-security-policy-the-pages-settings-blocked-the-loading-of-a-resource

@Crewxx
Copy link

Crewxx commented May 24, 2022

Greetings @thealphadollar, have you noticed the new linkedin features in connecting? Linkedin added a pop up that you have to choose how you know each other then you have to select option before the connect buttons shows up thus making the script not able to connect. Please kindly fix. See image below
Thanks
lnkd

@thealphadollar
Copy link
Author

thealphadollar commented May 25, 2022

@Aliss20 @Crewxx Thank you for bringing forward the issues. Unfortunately, I'm not actively maintaining the project and prioritising my other works. Hence, I would wait for someone to solve the problem - and update the doc then.

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