-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
72 lines (60 loc) · 1.82 KB
/
background.js
File metadata and controls
72 lines (60 loc) · 1.82 KB
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
console.log("Imagine background script loaded");
chrome.contextMenus.create(
{
id: "imagine-job-email-insert",
title: "Log job details",
contexts: ["page"],
},
() => {
console.log("Context menu created successfully");
}
);
// Listen for messages from content scripts
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
console.log("Background received message:", request);
if (request.action === "fillJobDetails") {
console.log("Forwarding job details to Google Forms page");
// Find the Google Forms tab and send the job details
// TODO: check if the tab is already open, otherwise open it
chrome.tabs.query({ url: "https://docs.google.com/forms/*" }, (tabs) => {
if (tabs.length > 0) {
chrome.tabs.sendMessage(
tabs[0].id,
{
action: "fillJobDetails",
content: request.content,
},
(response) => {
if (chrome.runtime.lastError) {
console.error(
"Error forwarding to Google Forms:",
chrome.runtime.lastError
);
} else {
console.log("Job details forwarded successfully");
}
}
);
sendResponse({
success: true,
message: "Job details forwarded successfully",
});
} else {
console.log("No Google Forms tab found to forward job details");
}
});
return true; // Keep message channel open
}
});
chrome.contextMenus.onClicked.addListener((info, tab) => {
console.log("Context menu clicked:", info, tab);
// Send message to content script to get job details
console.log("Sending message to Xing content script");
chrome.tabs.sendMessage(tab.id, { action: "getJobDetails" }, (response) => {
if (chrome.runtime.lastError) {
console.error("Error sending message:", chrome.runtime.lastError);
} else {
console.log("Job details received:", response);
}
});
});