-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
39 lines (33 loc) · 1.32 KB
/
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
36
37
38
39
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === 'downloadConversation') {
window.postMessage({ type: 'downloadConversation' }, '*');
}
});
function injectScriptFile(filePath) {
const script = document.createElement('script');
script.src = chrome.runtime.getURL(filePath);
(document.head || document.documentElement).appendChild(script);
}
injectScriptFile('shared.js');
injectScriptFile('inject.js');
document.onreadystatechange = () => {
if (document.readyState === 'interactive' || document.readyState === 'complete') {
const downloadButton = document.createElement('button');
downloadButton.innerText = 'Save';
downloadButton.className = 'download-button';
const icon = document.createElement('i');
downloadButton.appendChild(icon);
document.body.appendChild(downloadButton);
downloadButton.addEventListener('click', () => {
window.postMessage({ type: 'downloadConversation' }, '*');
});
}
}
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
console.log(request.action);
if (request.action === "searchLocalStorage") {
const searchTerm = request.searchTerm;
const searchResults = searchItems(searchTerm);
sendResponse(searchResults);
}
});