Skip to content

Instantly share code, notes, and snippets.

@WisaniShilumani
Last active May 18, 2020 20:00
Show Gist options
  • Save WisaniShilumani/6714cae8c1339d68c59d1d6801be2b54 to your computer and use it in GitHub Desktop.
Save WisaniShilumani/6714cae8c1339d68c59d1d6801be2b54 to your computer and use it in GitHub Desktop.
Add from search
const speed = 500;
const connectButtons = document.querySelectorAll(
'.search-result__actions button[data-control-name="srp_profile_actions"]'
);
// ==================== INSTRUCTIONS ========================= //
// =========================================================== //
// 1. Go to LinkedIn Search
// 2. Search for People in an industry e.g. CEO
// 3. Click on people until you see a list of people you can connect with
// 4. Open the console on your browser. (Right click anywhere and click Inspect)
// 5. IMPORTANT: EDIT THE MESSAGE BELOW. Replace <ADD YOUR MESSAGE HERE> with your message
// 6. Paste all of this code into the console and hit Enter
const message = (name) => {
return `Hey ${name}, <ADD YOUR MESSAGE HERE>`;
};
const addUsers = (buttons, index = 0) => {
if (buttons.length && index <= buttons.length - 1) {
buttons[index].click();
setTimeout(() => {
const addNoteButton = document.querySelector('button[aria-label="Add a note"]');
if (!addNoteButton) return addUsers(buttons, index + 1);
addNoteButton.click();
setTimeout(() => {
const lowerCaseName = document
.querySelector('h2#send-invite-modal')
.textContent.replace('Invite ', '')
.replace(' to connect', '')
.split(' ')
.filter((part) => part.length > 2)[0]
.replace(/ /g, '')
.replace(/[^a-zA-Z0-9 -]/g, '')
.toLowerCase();
const name = lowerCaseName.replace(/^./, lowerCaseName[0].toUpperCase());
console.log(name);
setTimeout(() => {
document.querySelector('textarea[name="message"]').value = message(name);
setTimeout(() => {
const sendButton = document.querySelector('button[aria-label="Send invitation"]');
if (!sendButton || sendButton.hasAttribute('disabled')) {
const cancelButton = document.querySelector('button[aria-label="Cancel adding a note"]');
cancelButton.click();
setTimeout(() => addUsers(buttons, index + 1), 1000);
}
sendButton.click();
if (index < buttons.length - 1) {
setTimeout(() => {
addUsers(buttons, index + 1);
}, speed);
}
}, speed);
}, speed);
}, speed);
}, speed);
} else {
window.scrollTo(0, 3000);
setTimeout(() => {
const nextButton = document.querySelector('button[aria-label="Next"]');
nextButton.click();
setTimeout(() => {
const newConnectButtons = document.querySelectorAll(
'.search-result__actions button[data-control-name="srp_profile_actions"]'
);
window.scrollTo(0, 3000);
setTimeout(() => {
addUsers(newConnectButtons);
}, 2000);
}, 5000);
}, 2000);
}
};
window.scrollTo(0, 3000);
setTimeout(() => {
addUsers(connectButtons);
}, 2000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment