Skip to content

Commit

Permalink
Add cv search (#677)
Browse files Browse the repository at this point in the history
  • Loading branch information
the1812 committed Mar 18, 2023
1 parent b4f3c3b commit c9bc402
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
37 changes: 37 additions & 0 deletions registry/lib/plugins/launch-bar/cv-search/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { LaunchBarActionProvider } from '@/components/launch-bar/launch-bar-action'
import type { PluginMetadata } from '@/plugins/plugin'
import { getJson } from '@/core/ajax'

export const plugin: PluginMetadata = {
name: 'launchBar.actions.cvSearch',
displayName: '搜索栏 - 专栏跳转',
async setup({ addData }) {
addData('launchBar.actions', (providers: LaunchBarActionProvider[]) => {
providers.push({
name: 'cvSearchProvider',
getActions: async input => {
const match = input.match(/^cv(\d+)$/)
if (!match) {
return []
}
const id = match[1]
const indexer = `cv${id}`
const json = await getJson(`https://api.bilibili.com/x/article/viewinfo?id=${id}`)
const { title } = lodash.get(json, 'data', {})
return [
{
name: title || indexer,
icon: 'mdi-open-in-new',
indexer,
description: '专栏跳转',
action: () => {
window.open(`https://www.bilibili.com/read/${indexer}`, '_blank')
},
order: 0,
},
]
},
})
})
},
}
16 changes: 9 additions & 7 deletions src/plugins/id-search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ const idMatches: IdSearchProvider[] = [
)
const data = lodash.get(json, 'data', {})
const { bvid, title } = data
const indexer = `av${match[1]}`

return {
name: title,
name: title || indexer,
description: 'av号跳转',
indexer: `av${match[1]}`,
indexer,
link: `https://www.bilibili.com/av${match[1]}`,
extraActions: bvid ? await getCopyItem('BV号', bvid, `av${match[1]}`) : [],
extraActions: bvid ? await getCopyItem('BV号', bvid, indexer) : [],
}
},
},
Expand All @@ -47,20 +48,21 @@ const idMatches: IdSearchProvider[] = [
)
const data = lodash.get(json, 'data', {})
const { aid, title } = data
const indexer = `BV${match[1]}`

return {
name: title,
name: title || indexer,
description: 'BV号跳转',
indexer: `BV${match[1]}`,
indexer,
link: `https://www.bilibili.com/BV${match[1]}`,
extraActions: aid ? await getCopyItem('av号', `av${aid}`, `BV${match[1]}`) : [],
extraActions: aid ? await getCopyItem('av号', `av${aid}`, indexer) : [],
}
},
},
]
export const plugin: PluginMetadata = {
name: 'launchBar.actions.IDSearch',
displayName: 'ID搜索快速跳转',
displayName: '搜索栏 - 视频跳转',
async setup() {
const { addData } = await import('../data')
const { LaunchBarActionProviders } = await import('@/components/launch-bar/launch-bar-action')
Expand Down

0 comments on commit c9bc402

Please sign in to comment.