mirror of
https://github.com/wassname/chatGPTBox.git
synced 2026-07-23 12:50:47 +08:00
chore: menu action source
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { getCoreContentText } from '../../utils/get-core-content-text'
|
||||
import Browser from 'webextension-polyfill'
|
||||
import { getUserConfig } from '../../config/index.mjs'
|
||||
import { openUrl } from '../../utils/index.mjs'
|
||||
|
||||
export const config = {
|
||||
newChat: {
|
||||
@@ -16,27 +18,49 @@ export const config = {
|
||||
},
|
||||
openConversationPage: {
|
||||
label: 'Open Conversation Page',
|
||||
action: async () => {
|
||||
Browser.runtime.sendMessage({
|
||||
type: 'OPEN_URL',
|
||||
data: {
|
||||
url: Browser.runtime.getURL('IndependentPanel.html'),
|
||||
},
|
||||
})
|
||||
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 () => {
|
||||
Browser.runtime.sendMessage({
|
||||
type: 'OPEN_CHAT_WINDOW',
|
||||
data: {},
|
||||
})
|
||||
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: {},
|
||||
})
|
||||
}
|
||||
},
|
||||
},
|
||||
closeAllChats: {
|
||||
label: 'Close All Chats In This Page',
|
||||
action: async () => {
|
||||
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',
|
||||
|
||||
Reference in New Issue
Block a user