-
Notifications
You must be signed in to change notification settings - Fork 493
/
Copy pathscript-2.js
111 lines (103 loc) · 3.12 KB
/
script-2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//function to pause the code
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.quertSelector(
`#${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.quertSelectorAll(
"button[aria-label^='Add a note']"
)[0];
const h2 = document.getElementById("send-invite-modal").innerHTML;
// to select the profile
if (h2.trim() === "Connect") {
const dismiss = document.querySelector("butto[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");
// message you want to send
textarea.value = `Hey ${name}, Let's 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"); // to select search results
// to select indivdual profiles
profiles.forEach(profile => {
const connectBtn = document.querySelector(
`#${profile.id} button[aria-label^='Connect']`
);
if (connectBtn === null) {
profile.parentNode.removeChild(profile);
}
});
// to check the last profile or no profiles
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();