-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
35 lines (30 loc) · 933 Bytes
/
content.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
chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
if (message.action === "contentToInject") {
const task = message.textToInject;
insertTaskContent(task);
}
});
function insertTaskContent(task) {
const dashboardSidebar = document.querySelector(".dashboard-sidebar");
if (dashboardSidebar) {
const taskContainer = document.createElement("div");
task.forEach((taskItem, index) => {
const taskElement = document.createElement("div");
taskElement.textContent = `Task ${index + 1}: ${
taskItem.task
}, Time: ${new Date(taskItem.time).toLocaleString(undefined, {
day: "numeric",
month: "short",
year: "numeric",
hour: "numeric",
minute: "numeric",
})}`;
taskContainer.appendChild(taskElement);
});
dashboardSidebar.appendChild(taskContainer);
} else {
console.log(
"Target div not found. Make sure the page structure is as expected."
);
}
}