-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcontent.js
More file actions
42 lines (35 loc) · 1.09 KB
/
content.js
File metadata and controls
42 lines (35 loc) · 1.09 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
import { getExtractor } from './extractors';
import { logMarian } from './shared/utils.js';
async function getDetails() {
const url = window.location.href;
logMarian(`Current URL: ${url}`);
const extractor = getExtractor(url);
if (extractor == undefined) return {};
logMarian(`Getting details from ${extractor}`)
return await extractor.getDetails()
}
chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
if (msg === 'ping_content') {
sendResponse('pong');
return false;
}
if (msg === 'getDetails') {
const send = async () => {
try {
const details = await getDetails();
sendResponse(details);
} catch (e) {
logMarian("Error getting info", e);
sendResponse({ __marian_error: e.message || String(e) });
}
};
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', send, { once: true });
} else {
send();
}
// Important: keep the message channel open for async response
return true;
}
});
console.log('[👩🏻🏫 Marian] content.js loaded');