This commit is contained in:
IndieKKY
2024-10-05 21:00:00 +08:00
parent 1bae3f8406
commit b44a73cd2f

View File

@@ -85,18 +85,25 @@ chrome.runtime.onMessage.addListener((event: MessageData, sender: chrome.runtime
//点击扩展图标
chrome.action.onClicked.addListener(async (tab) => {
chrome.storage.sync.get(STORAGE_ENV, envDatas => {
chrome.storage.sync.get(STORAGE_ENV, (envDatas) => {
const envDataStr = envDatas[STORAGE_ENV]
const envData = envDataStr ? JSON.parse(envDataStr) : {}
if (envData.sidePanel) {
chrome.sidePanel.setOptions({
enabled: true,
tabId: tab.id!,
path: 'sidepanel.html?tabId=' + tab.id,
path: '/sidepanel.html?tabId=' + tab.id,
})
chrome.sidePanel.setPanelBehavior({
openPanelOnActionClick: true,
})
chrome.sidePanel.open({
tabId: tab.id!,
})
} else {
chrome.sidePanel.setPanelBehavior({
openPanelOnActionClick: false,
})
extensionMessage.broadcastMessageExact([tab.id!], MESSAGE_TARGET_INJECT, MESSAGE_TO_INJECT_TOGGLE_DISPLAY).catch(console.error)
}
})