-
Notifications
You must be signed in to change notification settings - Fork 854
Expand file tree
/
Copy pathindex.mjs
More file actions
84 lines (83 loc) · 2.62 KB
/
index.mjs
File metadata and controls
84 lines (83 loc) · 2.62 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { getCoreContentText } from '../../utils/get-core-content-text'
import Browser from 'webextension-polyfill'
import { getUserConfig } from '../../config/index.mjs'
import { openUrl } from '../../utils/open-url'
export const config = {
newChat: {
label: 'New Chat',
genPrompt: async () => {
return ''
},
},
summarizePage: {
label: 'Summarize Page',
genPrompt: async () => {
return `You are an expert summarizer. Carefully analyze the following web page content and provide a concise summary focusing on the key points:\n${getCoreContentText()}`
},
},
openConversationPage: {
label: 'Open Conversation Page',
action: async (fromBackground) => {
console.debug('action is from background', fromBackground)
if (fromBackground) {
openUrl(Browser.runtime.getURL('IndependentPanel.html'))
} else {
Browser.runtime.sendMessage({
type: 'OPEN_URL',
data: {
url: Browser.runtime.getURL('IndependentPanel.html'),
},
})
}
},
},
openConversationWindow: {
label: 'Open Conversation Window',
action: async (fromBackground) => {
console.debug('action is from background', fromBackground)
if (fromBackground) {
const config = await getUserConfig()
const url = Browser.runtime.getURL('IndependentPanel.html')
const tabs = await Browser.tabs.query({ url: url, windowType: 'popup' })
if (!config.alwaysCreateNewConversationWindow && tabs.length > 0)
await Browser.windows.update(tabs[0].windowId, { focused: true })
else
await Browser.windows.create({
url: url,
type: 'popup',
width: 500,
height: 650,
})
} else {
Browser.runtime.sendMessage({
type: 'OPEN_CHAT_WINDOW',
data: {},
})
}
},
},
openSidePanel: {
label: 'Open Side Panel',
action: (fromBackground, tab) => {
console.debug('action is from background', fromBackground)
if (fromBackground) {
// eslint-disable-next-line no-undef
return chrome.sidePanel.open({ windowId: tab.windowId, tabId: tab.id })
}
// side panel is not supported
return undefined
},
},
closeAllChats: {
label: 'Close All Chats In This Page',
action: async (fromBackground) => {
console.debug('action is from background', fromBackground)
Browser.tabs.query({ active: true, currentWindow: true }).then((tabs) => {
Browser.tabs.sendMessage(tabs[0].id, {
type: 'CLOSE_CHATS',
data: {},
})
})
},
},
}