Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions entrypoints/background.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import COMMAND_MAP, { CommandTypes } from "./common/commands";
import { getCommandFn } from "./common/utils";

export default defineBackground(() => {
// console.log('Hello background!', { id: browser.runtime.id });
// console.log('Hello background!2 ', chrome.action);
Expand Down Expand Up @@ -27,4 +30,10 @@ export default defineBackground(() => {
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
setIcon(tab)
});

/** 快捷键唤醒插件 */
chrome.commands.onCommand.addListener((command) => {
const commandFn = getCommandFn(command)
commandFn(command)
});
})
21 changes: 21 additions & 0 deletions entrypoints/common/commands/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/** 唤醒插件弹窗 */
const showPopup = (command: string) => {
chrome.action.openPopup();
}

export enum Command {
/** 打开插件 */
ShowPopup = 'show_popup',
/** 唤醒配置页 */
OpenSettings = 'open_settings',
}

export type CommandTypes = `${Command}`

const COMMAND_MAP = {
[Command.ShowPopup]: showPopup
} as {
[key: string]: (command: string) => void
}

export default COMMAND_MAP;
2 changes: 1 addition & 1 deletion entrypoints/common/i18n/language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const i18nMap = {
'searchTipMac': { en: 'Find Your Link(⌘ + F)', zh: '查找链接(⌘ + F)' },
'searchTipWin': { en: 'Find Your Link(Ctrl + F)', zh: '查找链接(Ctrl + F)' },
'searchPlaceholder': { en: 'Just Input', zh: '随便输入点' },
'TagTip': { en: 'Add tags when add Site', zh: '添加链接时可增加标签' },
'TagTip': { en: 'Tags can be added when saving a link. The plugin can be activated using keyboard shortcuts (Windows: Ctrl+Shift+K, Mac: Command+Shift+K)', zh: '添加链接时可增加标签,可通过快捷键唤醒插件(Windows: Ctrl+Shift+K, Mac: Command+Shift+K)' },
};


Expand Down
6 changes: 6 additions & 0 deletions entrypoints/common/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@


// get facicon

import COMMAND_MAP from "./commands";

// https://github.com/faviconkit/javascript-api
export const getFavicon = (url, size = 32) => {
const favIconUrl = `chrome-extension://${chrome.runtime.id}/_favicon/?pageUrl=${encodeURIComponent(url)}&size=${32}`;
Expand Down Expand Up @@ -68,3 +71,6 @@ function diffTrees(oldTree: TreeNode | undefined, newTree: TreeNode | undefined)
}


export const getCommandFn = (command: string) => {
return COMMAND_MAP[command] || (() => {})
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"antd": "^5.16.2",
"fuse.js": "^7.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react-dom": "^18.2.0",
"tinykeys": "^3.0.0"
},
"devDependencies": {
"@types/chrome": "^0.0.268",
Expand Down
Loading