-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcontent-script.js
69 lines (62 loc) · 1.97 KB
/
content-script.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
const getCalendar = (initialDate) => {
document.querySelector("#calendarview")?.remove();
document.querySelector("bdv-time-tracker-list")?.remove();
const calendarView = document.createElement("div");
calendarView.className = "calendar-view";
calendarView.id = "calendarview";
document.querySelector(".open-hours-panel").appendChild(calendarView);
const calendarEl = document.getElementById("calendarview");
const calendar = new FullCalendar.Calendar(calendarEl, {
initialView: "dayGridMonth",
headerToolbar: false,
initialDate,
dateClick: function (value) {
if (!document.querySelector('[formcontrolname="recordDate"]')) {
document
.querySelector(
".bdv-button-appearance-solid.bdv-button-color-secondary.bdv-button-size-md"
)
?.click();
}
setTimeout(() => {
const inputDate = document.querySelector(
'[formcontrolname="recordDate"]'
);
if (inputDate) {
inputDate.value = value.date;
//data.dateStr
inputDate.dispatchEvent(new Event("input"));
inputDate.dispatchEvent(new Event("blur"));
}
}, 400);
},
});
calendar.render();
return calendar;
};
chrome.runtime.onMessage.addListener((media, sender, sendResponse) => {
if (media.event === "mountdatacalendar") {
const dates = Object.keys(media.data);
const initialDate = dates[0].split("T").shift();
const calendar = getCalendar(initialDate);
for (day of dates) {
const data = day.split("T").shift();
let daySum = 0;
media.data[day].forEach((event) => {
calendar.addEvent({
title: event.hours + "h - " + event.descriptionName,
start: data,
allDay: true,
color: "grey",
});
daySum += event.hours;
});
calendar.addEvent({
title: "Total: " + daySum + "h ",
start: data,
allDay: true,
color: "blue",
});
}
}
});