-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsocialite-tracker.js
84 lines (82 loc) · 2.52 KB
/
socialite-tracker.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
async function socialiteTracker() {
function wait(time) {
return new Promise(resolve => {
setTimeout(() => {
resolve();
}, time);
});
}
await wait(1000);
const listEl = document.getElementById("__next").children[3];
async function getAttended(person) {
person.click();
await wait(2000)
person.click();
await wait(2000);
const personDetails = document.querySelector("[aria-modal=true]");
//console.log(personDetails);
const data = personDetails.children[0].children[0].children[1].lastChild;
if (data.tagName !== 'SECTION') {
return { attended: 0, hosted: 0 };
}
function getNum(el) {
const badges = el.getAttribute("srcset");
const badge = badges.split(',')[0];
const width = badge.split(' ')[1];
const withoutWidth = badge.split(width).join("");
const num = parseInt(withoutWidth.replace(/[^0-9]/g, ''));
return num;
}
const attended = getNum(data.children[0]);
const hostedEl = data.children[1];
const hosted = hostedEl === undefined ? 0 : getNum(hostedEl);
return { attended, hosted };
}
const people = listEl.children;
const names = new Map();
const localStorageKey = "progress";
function getOrSet() {
const progress = localStorage.getItem(localStorageKey);
if (!progress) {
localStorage.setItem(localStorageKey, JSON.stringify({}));
return {};
}
return JSON.parse(progress);
}
function save(res) {
localStorage.setItem(localStorageKey, JSON.stringify(res));
}
const results = getOrSet();
const total = people.length;
let i = 0;
for (const person of people) {
i++;
const name = person.children[0].children[1].innerHTML;
const shared = parseInt(person.children[1].innerHTML);
console.log(`${i} / ${total} (${name})`);
let num = 1;
if (names.has(name)) {
num = names.get(name) + 1;
}
names.set(name, num);
const resultKey = `${name}-${num}`;
if (resultKey in results) continue;
const { attended, hosted } = await getAttended(person);
const curResult = {
name,
shared,
attended,
hosted
}
results[resultKey] = curResult;
save(results);
}
const sorted = Object.entries(results).sort((a, b) => b[1].attended - a[1].attended);
for ([k, { name: n, attended, hosted, shared }] of sorted) {
function pad(s, n = 3) {
return (""+s).padStart(n, " ");
}
console.log(`${pad(n, 30)}: ${pad(attended)} attended, ${pad(hosted)} hosted, ${pad(shared)} shared`);
}
}
socialiteTracker();