-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathsaveViewData.js
106 lines (80 loc) · 3.31 KB
/
saveViewData.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
/*/
You only need the automatic scroller on the first execution if you plan to run this regularly.
Delete the following lines if you do not want the autoScroll-to-end:
lines 11-25, line 94, line 106
The apps script currently ignores adding new rows if the profile link already exists within the spreadsheet.
I started building a smarter system to add the person again if they view the profile multiple times, but it is not ready.
Also, be sure to delete these comments before converting to a bookmarklet.
/*/
var webAppURL = "yourappURLgoesHere";
var prodElm = parseInt(grouped(/^(.+?)\s*profile/.exec(document.getElementsByClassName("me-wvmp-views__profile-views Sans-13px-black-55% pr5")[0].innerText), 1));
var numScrollEventsNeeded = Math.round((prodElm - 6) / 9);
function timedScroller(num) {
setTimeout(() => {
window.scrollTo(0, document.body.scrollHeight);
}, num);
}
for (i = 0; i < numScrollEventsNeeded; i++) {
timedScroller(i * 1000);
}
function grouped(e, n) {
if (e != null) {
return e[n].toString();
} else {
return "";
}
}
function validate(e, n, t) {
if (e != null) {
if (e.length > (n)) {
if (t == "href") {
return e[n].href;
}
if (t == "innerText") {
return e[n].innerText;
}
if (t == "innerHTML") {
return e[n].innerHTML;
}
if (t = 'next') {
return e[n];
}
}
} else {
return '';
}
}
function clearOut(str) {
if (str == undefined) {
return '';
} else {
return str.replace(/undefined|\&|\?|\#|"|\=/g, '');
}
}
setTimeout(() => {
var profContainer = document.getElementsByTagName("article");
var dataArray = [];
for (i = 1; i < (profContainer.length - 1); i++) {
var profLink = grouped(/linkedin\.com\/in\/(.+?)(?=\/|$)/.exec(validate(profContainer[i].getElementsByTagName("a"), 0, "href")), 1);
var seen = validate(profContainer[i].getElementsByClassName("me-wvmp-viewer-card__time-ago"), 0, "innerText");
var name = validate(validate(profContainer[i].getElementsByTagName("h2"), 0, 'next').getElementsByTagName("span"), 0, "innerText");
var dist = validate(validate(profContainer[i].getElementsByTagName("h2"), 0, 'next').getElementsByTagName("span"), 1, "innerText");
var work = validate(profContainer[i].getElementsByClassName("me-wvmp-viewer-card__viewer-headline"), 0, "innerText");
var foundVia = validate(profContainer[i].getElementsByClassName("me-wvmp-viewer-card__found-via"), 0, "innerText");
if (work == undefined) {
work = validate(validate(profContainer[i].getElementsByTagName("h2"), 0, 'next').getElementsByTagName("p"), 0, 'innerText');
}
dataArray.push('["' + profLink + '","' + clearOut(name) + '","' + clearOut(work) + '","' + clearOut(seen) + '","' + clearOut(dist) + '","' + clearOut(foundVia).replace(/Found you via /, '') + '"]');
}
var partitionArray = (array, size) => array.map((e, i) => (i % size === 0) ? array.slice(i, i + size) : null).filter((e) => e);
var arrays = partitionArray(dataArray, 30);
function timedPageOpen(fun, num) {
setTimeout(() => {
window.open(fun);
}, num);
}
for (a=0; a<(arrays.length); a++) {
var sendthis = encodeURIComponent('[' + arrays[a].toString() + ']');
timedPageOpen(webAppURL+'?out=' + sendthis, (a * 533));
}
}, ((numScrollEventsNeeded * 1001) + 1333));