diff --git a/source/background-scripts/commands.ts b/source/background-scripts/commands.ts new file mode 100644 index 0000000..90bb678 --- /dev/null +++ b/source/background-scripts/commands.ts @@ -0,0 +1,7 @@ +import {toggleAllRedirects} from '../utilities/toggle-all-redirects.js'; + +export async function onCommandsHandler(command: string): Promise { + if (command === 'toggleAllRedirects') { + await toggleAllRedirects(); + } +} diff --git a/source/background-scripts/initialize.ts b/source/background-scripts/initialize.ts index bf2dfcf..30d9132 100644 --- a/source/background-scripts/initialize.ts +++ b/source/background-scripts/initialize.ts @@ -2,6 +2,7 @@ import browser from 'webextension-polyfill'; import storage from '../redirect/storage.js'; import {updateBadge} from '../utilities/badge.js'; +import {onCommandsHandler} from './commands.js'; import { contextClicked, getContextMenus, @@ -97,6 +98,8 @@ browser.contextMenus.onClicked.addListener(async (info, tab) => { await contextClicked(contextMenuIds, info, tab); }); +browser.commands.onCommand.addListener(onCommandsHandler); + if (import.meta.env.VITE_BROWSER === 'chromium') { browser.action.onClicked.addListener(browserActionClicked); } else { diff --git a/source/manifest.ts b/source/manifest.ts index 57caec0..9aa8b25 100644 --- a/source/manifest.ts +++ b/source/manifest.ts @@ -12,6 +12,15 @@ export default function createManifest( page: 'options/index.html', open_in_tab: true, }, + commands: { + toggleAllRedirects: { + description: + "Toggle all redirects, this does the same as the extension icon's right-click option.", + suggested_key: { + default: 'Alt+Shift+R', + }, + }, + }, }; const icons = {