mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
Add cv search (#677)
This commit is contained in:
parent
b4f3c3bd07
commit
c9bc4024ef
37
registry/lib/plugins/launch-bar/cv-search/index.ts
Normal file
37
registry/lib/plugins/launch-bar/cv-search/index.ts
Normal file
@ -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,
|
||||
},
|
||||
]
|
||||
},
|
||||
})
|
||||
})
|
||||
},
|
||||
}
|
||||
@ -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) : [],
|
||||
}
|
||||
},
|
||||
},
|
||||
@ -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')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user