-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconnections.js
92 lines (81 loc) · 2.65 KB
/
connections.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
// 1. head over to https://www.linkedin.com/mynetwork/
// 2. make sure your LinkedIn is in English and you are login to your account
// 3. paste this script on chrome dev tools at your own risk on the console
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();
// after your get connections out of limit message then just refresh the page and you are good to go.
// Thank you!!