mirror of
https://github.com/wassname/chatGPTBox.git
synced 2026-08-01 12:20:35 +08:00
@@ -126,6 +126,19 @@ Browser.runtime.onMessage.addListener(async (message) => {
|
||||
}
|
||||
})
|
||||
|
||||
Browser.commands.onCommand.addListener(async (command) => {
|
||||
const currentTab = (await Browser.tabs.query({ active: true, currentWindow: true }))[0]
|
||||
const message = {
|
||||
itemId: command,
|
||||
selectionText: '',
|
||||
useMenuPosition: false,
|
||||
}
|
||||
Browser.tabs.sendMessage(currentTab.id, {
|
||||
type: 'CREATE_CHAT',
|
||||
data: message,
|
||||
})
|
||||
})
|
||||
|
||||
function refreshMenu() {
|
||||
Browser.contextMenus.removeAll().then(() => {
|
||||
const menuId = 'ChatGPTBox-Menu'
|
||||
@@ -164,10 +177,11 @@ function refreshMenu() {
|
||||
const message = {
|
||||
itemId: info.menuItemId.replace(menuId, ''),
|
||||
selectionText: info.selectionText,
|
||||
useMenuPosition: true,
|
||||
}
|
||||
console.debug('menu clicked', message)
|
||||
Browser.tabs.sendMessage(tab.id, {
|
||||
type: 'CREATE_MENU',
|
||||
type: 'CREATE_CHAT',
|
||||
data: message,
|
||||
})
|
||||
})
|
||||
|
||||
@@ -218,7 +218,7 @@ async function prepareForRightClickMenu() {
|
||||
})
|
||||
|
||||
Browser.runtime.onMessage.addListener(async (message) => {
|
||||
if (message.type === 'CREATE_MENU') {
|
||||
if (message.type === 'CREATE_CHAT') {
|
||||
const data = message.data
|
||||
let prompt = ''
|
||||
if (data.itemId in toolsConfig) {
|
||||
@@ -228,7 +228,9 @@ async function prepareForRightClickMenu() {
|
||||
if (prompt) prompt = cropText(`Reply in ${await getPreferredLanguage()}.\n` + prompt)
|
||||
}
|
||||
|
||||
const position = { x: menuX, y: menuY }
|
||||
const position = data.useMenuPosition
|
||||
? { x: menuX, y: menuY }
|
||||
: { x: window.innerWidth / 2 - 300, y: window.innerHeight / 2 - 200 }
|
||||
const container = createElementAtPosition(position.x, position.y)
|
||||
container.className = 'chatgptbox-toolbar-container-not-queryable'
|
||||
render(
|
||||
|
||||
+18
-1
@@ -14,6 +14,7 @@
|
||||
"https://*.bing.com/"
|
||||
],
|
||||
"permissions": [
|
||||
"commands",
|
||||
"cookies",
|
||||
"storage",
|
||||
"contextMenus"
|
||||
@@ -47,5 +48,21 @@
|
||||
"<all_urls>"
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
"commands": {
|
||||
"newChat": {
|
||||
"suggested_key": {
|
||||
"default": "Ctrl+B",
|
||||
"mac": "MacCtrl+B"
|
||||
},
|
||||
"description": "Create a new chat"
|
||||
},
|
||||
"summarizePage": {
|
||||
"suggested_key": {
|
||||
"default": "Alt+B",
|
||||
"mac": "Alt+B"
|
||||
},
|
||||
"description": "Summarize this page"
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
-1
@@ -10,6 +10,7 @@
|
||||
"128": "logo.png"
|
||||
},
|
||||
"permissions": [
|
||||
"commands",
|
||||
"cookies",
|
||||
"storage",
|
||||
"contextMenus",
|
||||
@@ -40,5 +41,21 @@
|
||||
],
|
||||
"web_accessible_resources": [
|
||||
"*.png"
|
||||
]
|
||||
],
|
||||
"commands": {
|
||||
"newChat": {
|
||||
"suggested_key": {
|
||||
"default": "Ctrl+B",
|
||||
"mac": "MacCtrl+B"
|
||||
},
|
||||
"description": "Create a new chat"
|
||||
},
|
||||
"summarizePage": {
|
||||
"suggested_key": {
|
||||
"default": "Alt+B",
|
||||
"mac": "Alt+B"
|
||||
},
|
||||
"description": "Summarize this page"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user