Skip to content

Commit 162afd8

Browse files
committed
chore
1 parent f460417 commit 162afd8

File tree

2 files changed

+32
-13
lines changed

2 files changed

+32
-13
lines changed

src/background/index.mjs

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -152,18 +152,26 @@ Browser.runtime.onMessage.addListener(async (message) => {
152152
})
153153

154154
Browser.commands.onCommand.addListener(async (command) => {
155-
const currentTab = (await Browser.tabs.query({ active: true, currentWindow: true }))[0]
156155
const message = {
157156
itemId: command,
158157
selectionText: '',
159158
useMenuPosition: false,
160159
}
161160
console.debug('command triggered', message)
162-
if (command in menuConfig && menuConfig[command].action) menuConfig[command].action()
163-
Browser.tabs.sendMessage(currentTab.id, {
164-
type: 'CREATE_CHAT',
165-
data: message,
166-
})
161+
162+
if (command in menuConfig) {
163+
if (menuConfig[command].action) {
164+
menuConfig[command].action()
165+
}
166+
167+
if (menuConfig[command].genPrompt) {
168+
const currentTab = (await Browser.tabs.query({ active: true, currentWindow: true }))[0]
169+
Browser.tabs.sendMessage(currentTab.id, {
170+
type: 'CREATE_CHAT',
171+
data: message,
172+
})
173+
}
174+
}
167175
})
168176

169177
function refreshMenu() {
@@ -212,12 +220,24 @@ function refreshMenu() {
212220
useMenuPosition: tab.id === currentTab.id,
213221
}
214222
console.debug('menu clicked', message)
215-
if (message.itemId in menuConfig && menuConfig[message.itemId].action)
216-
menuConfig[message.itemId].action()
217-
Browser.tabs.sendMessage(currentTab.id, {
218-
type: 'CREATE_CHAT',
219-
data: message,
220-
})
223+
224+
if (defaultConfig.selectionTools.includes(message.itemId)) {
225+
Browser.tabs.sendMessage(currentTab.id, {
226+
type: 'CREATE_CHAT',
227+
data: message,
228+
})
229+
} else if (message.itemId in menuConfig) {
230+
if (menuConfig[message.itemId].action) {
231+
menuConfig[message.itemId].action()
232+
}
233+
234+
if (menuConfig[message.itemId].genPrompt) {
235+
Browser.tabs.sendMessage(currentTab.id, {
236+
type: 'CREATE_CHAT',
237+
data: message,
238+
})
239+
}
240+
}
221241
})
222242
})
223243
})

src/content-script/index.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ async function run() {
304304
changeLanguage(lang)
305305
})
306306
Browser.runtime.onMessage.addListener(async (message) => {
307-
console.log(message)
308307
if (message.type === 'CHANGE_LANG') {
309308
const data = message.data
310309
changeLanguage(data.lang)

0 commit comments

Comments
 (0)