Last active
February 28, 2024 01:45
-
-
Save acoyfellow/0a5cb6959703a136e4f8be51b822fc44 to your computer and use it in GitHub Desktop.
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
function sleep(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
async function connect(profile, i) { | |
try { | |
const a=document.querySelector(`#${profile.id} a`); | |
if(a===null){ | |
run(); | |
return; | |
}; | |
const url = a.href; | |
const connectBtn = document.querySelector( | |
`#${profile.id} button[aria-label^='Connect']` | |
); | |
if (connectBtn === null && profiles && profiles[i + 1]) { | |
connect( | |
profiles[i + 1], | |
i + 1 | |
); | |
return; | |
} else if (connectBtn === null) { | |
run(); | |
return; | |
} | |
connectBtn.click(); | |
await sleep(2000); | |
const addNoteBtn = document.querySelectorAll( | |
"button[aria-label^='Add a note']" | |
)[0]; | |
const h2 = document.getElementById("send-invite-modal").innerHTML; | |
if (h2.trim() === "Connect") { | |
const dismiss = document.querySelector("button[aria-label^='Dismiss']"); | |
profile.parentNode.removeChild(profile); | |
dismiss.click(); | |
run(); | |
return; | |
} | |
if (addNoteBtn === null) { | |
run(); | |
return; | |
} | |
addNoteBtn.click(); | |
await sleep(1000); | |
const name = document | |
.getElementById("send-invite-modal") | |
.innerHTML.replace("Invite ", "") | |
.replace(" to connect", "") | |
.trim(); | |
const textarea = document.querySelector("#custom-message"); | |
textarea.value = `Hey ${name}, I'd be honored if we could connect here on LinkedIn :)`; | |
const sendInvitationBtn = document.querySelector( | |
"button[aria-label^='Send invitation']" | |
); | |
const http = new XMLHttpRequest(); | |
http.open("GET", url); | |
http.send(); | |
sendInvitationBtn.click(); | |
await sleep(2500); | |
run(); | |
console.log('Requested + Profile Visited:', i, name, url); | |
} catch (e) { | |
console.error(e); | |
if (profile) { | |
connect( | |
profile, | |
i | |
); | |
} | |
} | |
} | |
var connected = []; | |
var profiles = []; | |
async function run() { | |
window.scrollTo(0, document.body.scrollHeight); | |
await sleep(250); | |
profiles = document.querySelectorAll("li.search-result"); | |
profiles.forEach(profile => { | |
const connectBtn = document.querySelector( | |
`#${profile.id} button[aria-label^='Connect']` | |
); | |
if (connectBtn===null) { | |
profile.parentNode.removeChild(profile); | |
} | |
}); | |
if (profiles.length === 0) { | |
console.log("Next Page >"); | |
const nextPageBtn = document.querySelector("button[aria-label^='Next']"); | |
nextPageBtn.click(); | |
await sleep(3500); | |
run(); | |
} else { | |
connect( | |
profiles[connected.length], | |
connected.length | |
); | |
} | |
} | |
run(); |
It seems it stopped submitting the connect text and not clicking the next page.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was great! A shame it stopped working. It now tries to hit the connection button on the top left in Linkedin. Anyway to fix?