-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforeground.js
69 lines (56 loc) · 1.95 KB
/
foreground.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
function waitForElm(selector) {
return new Promise(resolve => {
if (document.querySelector(selector)) {
return resolve(document.querySelector(selector));
}
const observer = new MutationObserver(mutations => {
if (document.querySelector(selector)) {
resolve(document.querySelector(selector));
observer.disconnect();
}
});
observer.observe(document.body, {
childList: true,
subtree: true
});
});
}
waitForElm("div[aria-label*='event from']").then((elm) => {
// Register future clicks
document.querySelectorAll('button[title*="Go to"]').forEach(button => {
button.addEventListener('click', () => {
setTimeout(() => {
let calendarData = getCalendarData()
runAndShowStatistics(calendarData)
}, 1000)
})
})
// Element is almost ready, using a setTimeout to be actual ready
setTimeout(function() {
let calendarData = getCalendarData()
runAndShowStatistics(calendarData)
let ws = new WebSocket("ws://localhost:37123");
ws.onopen = function (event) {
console.log("Connected to outlook exporter backend");
console.log("Sending calendar data.", new Date())
let txt = JSON.stringify(calendarData)
console.log(txt)
ws.send(txt)
}
}, 3000);
});
function getCalendarData() {
// Test in browser console with: $("div[aria-label*='event from']")
let calendarEvents = document.querySelectorAll("div[aria-label*='event from']")
let calendarData = []
for (const event of calendarEvents) {
let title = event.getAttribute("title")
let label = event.getAttribute("aria-label")
let entry = {
title: title,
label: label,
}
calendarData.push(entry)
}
return calendarData
}