mirror of
https://github.com/wassname/chatGPTBox.git
synced 2026-07-17 11:26:00 +08:00
chore: menu action source
This commit is contained in:
@@ -12,7 +12,7 @@ export function registerCommands() {
|
||||
|
||||
if (command in menuConfig) {
|
||||
if (menuConfig[command].action) {
|
||||
menuConfig[command].action()
|
||||
menuConfig[command].action(true)
|
||||
}
|
||||
|
||||
if (menuConfig[command].genPrompt) {
|
||||
|
||||
@@ -57,7 +57,7 @@ export function refreshMenu() {
|
||||
})
|
||||
} else if (message.itemId in menuConfig) {
|
||||
if (menuConfig[message.itemId].action) {
|
||||
menuConfig[message.itemId].action()
|
||||
menuConfig[message.itemId].action(true)
|
||||
}
|
||||
|
||||
if (menuConfig[message.itemId].genPrompt) {
|
||||
|
||||
@@ -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',
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ getUserConfig().then(async (config) => {
|
||||
|
||||
if (config.clickIconAction in menuConfig) {
|
||||
if (menuConfig[config.clickIconAction].action) {
|
||||
menuConfig[config.clickIconAction].action()
|
||||
menuConfig[config.clickIconAction].action(false)
|
||||
}
|
||||
|
||||
if (menuConfig[config.clickIconAction].genPrompt) {
|
||||
|
||||
Reference in New Issue
Block a user