-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
43 lines (40 loc) · 1.49 KB
/
background.js
File metadata and controls
43 lines (40 loc) · 1.49 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
// This function runs when the extension is installed or updated
chrome.runtime.onInstalled.addListener(function() {
// log that the extension was installed
console.log('Extension installed');
});
// When DOM is loaded, execute content script
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
if (changeInfo.status === 'complete' && tab.url && tab.url.includes('openai.')) {
console.log("Exec tabs script on update:", chrome.runtime.id);
chrome.scripting.executeScript({
target: {tabId: tabId},
files: ['content.js']
});
}
});
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.action === "executeScript") {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
if (tabs[0]) {
chrome.scripting.executeScript({
target: {tabId: tabs[0].id},
files: ['content.js']
});
} else {
console.error("No active tab found.");
}
});
}
if (message.action === "saveFile") {
// process message chrome.runtime.sendMessage({action: "saveFile", filename: filename, file: file }, function(response) {});
console.log("Saving file:", message.filename);
const file_url = message.file_url;
const filename = message.filename;
chrome.downloads.download({
url: file_url,
filename: filename
});
}
return true;
});