Skip to content

Commit

Permalink
Add addOptionsContextMenu
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante committed Jun 26, 2024
1 parent 0e9f338 commit a1c3e7e
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import chromeP from 'webext-polyfill-kinda';
import {executeFunction} from 'webext-content-scripts';
import {isFirefox, isSafari} from 'webext-detect-page';

export type Target = {
tabId: number;
Expand Down Expand Up @@ -102,3 +103,22 @@ export function setActionPopup(
}
});
}

const optionsShortcut = 'WEBEXT_TOOLS_OPTIONS';

function onContextMenuClick({menuItemId}: chrome.contextMenus.OnClickData): void {
if (menuItemId === optionsShortcut) {
void chrome.runtime.openOptionsPage();
}
}

export function addOptionsContextMenu(): void {
if (isFirefox() || isSafari()) {
chrome.contextMenus.onClicked.addListener(onContextMenuClick);
chrome.contextMenus.create({
id: optionsShortcut,
title: 'Options…',
contexts: 'action' in chrome ? ['action'] : ['browser_action'],
});
}
}

0 comments on commit a1c3e7e

Please sign in to comment.