-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy patheventWorker.js
190 lines (154 loc) · 5.96 KB
/
eventWorker.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
var users = [];
var totalResultCount = 0;
var status = 0;
// Function to slow down the pace of attack
function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if (new Date().getTime() - start > milliseconds) {
break;
}
}
}
function userParse(jd) {
console.log(jd.elements.length);
for (e = 0; e < jd.elements.length; e++) {
if (jd.elements[e].hasOwnProperty('items')) {
for (x = 0; x < jd.elements[e].items.length; x++) {
var name = '';
var headline = '';
var subline = '';
var handle = '';
if (!jd.elements[e].items[x].itemUnion.hasOwnProperty('entityResult')) {
continue;
}
if (!jd.elements[e].items[x].itemUnion.entityResult.hasOwnProperty('title')) {
continue;
}
if (jd.elements[e].items[x].itemUnion.entityResult.title.hasOwnProperty('text')) {
name = jd.elements[e].items[x].itemUnion.entityResult.title.text;
}
if (name.includes('LinkedIn')) {
continue;
}
if (jd.elements[e].items[x].itemUnion.entityResult.hasOwnProperty('primarySubtitle') && jd.elements[e].items[x].itemUnion.entityResult.primarySubtitle.hasOwnProperty('text')) {
headline = jd.elements[e].items[x].itemUnion.entityResult.primarySubtitle.text;
}
if (jd.elements[e].items[x].itemUnion.entityResult.hasOwnProperty('secondarySubtitle') && jd.elements[e].items[x].itemUnion.entityResult.secondarySubtitle.hasOwnProperty('text')) {
subline = jd.elements[e].items[x].itemUnion.entityResult.secondarySubtitle.text;
}
var url = jd.elements[e].items[x].itemUnion.entityResult.navigationUrl.split('/');
handle = url[url.length-1].split('?')[0];
users.push(new Array(name, headline, subline, handle));
}
}
}
}
function getData(i, queryParameters, csrftoken, timeout)
{
sleep(timeout);
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
var url =
'https://www.linkedin.com/voyager/api/search/dash/clusters?decorationId=com.linkedin.voyager.dash.deco.search.SearchClusterCollection-92&origin=FACETED_SEARCH&q=all&query=(flagshipSearchIntent:SEARCH_SRP,queryParameters:(' +
queryParameters +
'),includeFiltersInResponse:false)&count=40&start=' +i * 40;
xhr.open('GET', url, false);
xhr.setRequestHeader('csrf-token', csrftoken);
xhr.setRequestHeader('x-restli-protocol-version', '2.0.0');
xhr.send();
if (xhr.status == 200) {
if(xhr.responseText.includes('You’ve reached the monthly limit for profile searches.')){
self.postMessage({ type: 'error', message: "Search limit reached" });
return;
}
var jd = JSON.parse(xhr.responseText);
if(jd.metadata.totalResultCount == 0){
self.postMessage({ type: 'error', message: "No results found" });
return;
}
if (totalResultCount == 0) {
totalResultCount = Math.ceil(jd.metadata.totalResultCount / 40);
}
if (totalResultCount > 25) {
totalResultCount = 25;
}
userParse(jd);
}
status = xhr.status;
}
self.addEventListener(
'message',
function (e) {
var data = e.data;
var currentCompany = '';
var geoUrn = '';
var profileLanguage = '';
var serviceCategory = '';
var title = '';
var industry = '';
try {
urlparts = decodeURI(data.url).split('?')[1].split('&');
} catch (err) {
self.postMessage({ type: 'error', message: 'Unable to parse URL, check you are on a search results page' });
}
queryParameters = '';
// Tidy up parts of url, bit sloppy but works?
for (i = 0; i < urlparts.length; i++) {
if (urlparts[i].includes('currentCompany')) {
currentCompany = urlparts[i].split('=')[1];
currentCompany = currentCompany.replace(/%2C/g, ',').replace('[', '').replace(']', '').replace(/"/g, '');
queryParameters += 'currentCompany:List(' + currentCompany + '),';
}
if (urlparts[i].includes('geoUrn')) {
geoUrn = urlparts[i].split('=')[1];
geoUrn = geoUrn.replace(/%2C/g, ',').replace('[', '').replace(']', '').replace(/"/g, '');
queryParameters += 'geoUrn:List(' + geoUrn + '),';
}
if (urlparts[i].includes('profileLanguage')) {
profileLanguage = urlparts[i].split('=')[1];
profileLanguage = profileLanguage.replace(/%2C/g, ',').replace('[', '').replace(']', '').replace(/"/g, '');
queryParameters += 'profileLanguage:List(' + profileLanguage + '),';
}
if (urlparts[i].includes('serviceCategory')) {
serviceCategory = urlparts[i].split('=')[1];
serviceCategory = serviceCategory.replace(/%2C/g, ',').replace('[', '').replace(']', '').replace(/"/g, '');
queryParameters += 'serviceCategory:List(' + serviceCategory + '),';
}
// industry=["96"]
if (urlparts[i].includes('industry')) {
industry = urlparts[i].split('=')[1];
industry = industry.replace(/%2C/g, ',').replace('[', '').replace(']', '').replace(/"/g, '');
queryParameters += 'industry:List(' + industry + '),';
}
if (urlparts[i].includes('title')) {
title = urlparts[i].split('=')[1];
title = title.replace(/%2C/g, ',').replace('[', '').replace(']', '').replace(/"/g, '');
queryParameters += 'title:List(' + title + '),';
}
}
queryParameters += 'resultType:List(PEOPLE)';
var i = 0;
var timeout = 500;
do {
//(function (i) {
setTimeout(getData(i, queryParameters, data.csrftoken, timeout), timeout);
if (status == 200){
}
else {
// handle errors better?
self.postMessage({ type: 'error', message: xhr.status });
console.log(xhr.status);
}
//})(i);
i++;
self.postMessage({
type: 'status',
page: i,
totalResultCount: totalResultCount,
});
} while (i < totalResultCount);
self.postMessage({ type: 'persondata', users: users });
},
false
);