support for chromium side panel (#111)

This commit is contained in:
josc146
2023-11-13 14:48:21 +08:00
parent d0fbc9fecb
commit 3e46fa29a6
19 changed files with 62 additions and 19 deletions
+2 -2
View File
@@ -2,7 +2,7 @@ import Browser from 'webextension-polyfill'
import { config as menuConfig } from '../content-script/menu-tools/index.mjs'
export function registerCommands() {
Browser.commands.onCommand.addListener(async (command) => {
Browser.commands.onCommand.addListener(async (command, tab) => {
const message = {
itemId: command,
selectionText: '',
@@ -12,7 +12,7 @@ export function registerCommands() {
if (command in menuConfig) {
if (menuConfig[command].action) {
menuConfig[command].action(true)
menuConfig[command].action(true, tab)
}
if (menuConfig[command].genPrompt) {
+10
View File
@@ -279,6 +279,16 @@ try {
},
['requestHeaders'],
)
Browser.tabs.onUpdated.addListener(async (tabId, info, tab) => {
if (!tab.url) return
// eslint-disable-next-line no-undef
await chrome.sidePanel.setOptions({
tabId,
path: 'IndependentPanel.html',
enabled: true,
})
})
} catch (error) {
console.log(error)
}
+1 -1
View File
@@ -57,7 +57,7 @@ export function refreshMenu() {
})
} else if (message.itemId in menuConfig) {
if (menuConfig[message.itemId].action) {
menuConfig[message.itemId].action(true)
menuConfig[message.itemId].action(true, tab)
}
if (menuConfig[message.itemId].genPrompt) {