Skip to content

Commit

Permalink
Add UID search (#677)
Browse files Browse the repository at this point in the history
  • Loading branch information
the1812 committed Apr 23, 2023
1 parent 60148c1 commit 0bb5355
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions registry/lib/plugins/launch-bar/uid-search/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
在输入 UID (用户 ID) 时, 提供对应的跳转选项.
32 changes: 32 additions & 0 deletions registry/lib/plugins/launch-bar/uid-search/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { LaunchBarActionProvider } from '@/components/launch-bar/launch-bar-action'
import type { PluginMetadata } from '@/plugins/plugin'
import { getJson } from '@/core/ajax'
import { createLinkAction, matchInput } from '../common'

export const plugin: PluginMetadata = {
name: 'launchBar.actions.uidSearch',
displayName: '搜索栏 - UID 跳转',
async setup({ addData }) {
addData('launchBar.actions', (providers: LaunchBarActionProvider[]) => {
providers.push({
name: 'uidSearchProvider',
getActions: async input => {
const { match, id, indexer } = matchInput(input, /^(uid)(\d+)$/)
if (!match) {
return []
}
const json = await getJson(`https://api.bilibili.com/x/space/wbi/acc/info?mid=${id}`)
const { name } = lodash.get(json, 'data', {})
return [
createLinkAction({
name,
description: '用户跳转',
link: `https://space.bilibili.com/${id}`,
indexer,
}),
]
},
})
})
},
}

0 comments on commit 0bb5355

Please sign in to comment.