-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontentScript.js
More file actions
46 lines (40 loc) · 1.38 KB
/
Copy pathcontentScript.js
File metadata and controls
46 lines (40 loc) · 1.38 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
(async () => {
try {
const src = chrome.runtime.getURL("./src/controllers/JobsController/index.js");
const contentMain = await import(src);
const fetchJobs = contentMain.default;
function ping() {
chrome.runtime.sendMessage('ping', response => {
if (chrome.runtime.lastError) {
setTimeout(ping, 1000);
} else {
chrome.runtime.sendMessage({
from: 'content',
subject: 'showPageAction',
});
}
});
}
ping();
chrome.runtime.onMessage.addListener(async (obj, sender, sendResponse) => {
const { type, tabId } = obj;
let response = { empty: true }
if (type === "SEARCH") {
console.log('SEARCH EVENT');
try {
await fetchJobs()
} catch (e) {
console.log('search err:', e);
response = { status: 400 };
sendResponse(response)
}
} else if (type === "TEST") {
sendResponse({ msg: "test msg" })
}
sendResponse(response)
});
console.log('CT Loaded correctly');
} catch (error) {
console.error('Error:', error);
}
})();