-
Notifications
You must be signed in to change notification settings - Fork 1
/
background.js
34 lines (28 loc) · 914 Bytes
/
background.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
chrome.runtime.onInstalled.addListener(() => {
console.log("ChatGPT-Extension loaded.")
const api_URL = "https://api.openai.com/v1";
chrome.storage.sync.set({"chatGPT_api_URL": api_URL}, function() {
console.log("API url saved - using: " + api_URL);
});
//create context menu
chrome.contextMenus.create({
id: "wording",
title: "Spelling and Grammar",
contexts: ["selection"],
});
chrome.contextMenus.create({
id: "improve",
title: "Suggest Improvement",
contexts: ["selection"],
});
});
// listener for context menu
chrome.contextMenus.onClicked.addListener(function (info, tab) {
chrome.storage.sync.get({
selectedModel: false,
chatGPT_api_key: false,
chatGPT_api_URL: false
}, function(items) {
chrome.tabs.sendMessage(tab.id, { config: items, info: info })
});
});