-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
在输入纯数字时, 提供以下选项: | ||
- 跳转至相应的视频 (视为 av 号) | ||
- 跳转至相应的专栏 (视为 cv 号) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import type { LaunchBarActionProvider } from '@/components/launch-bar/launch-bar-action' | ||
import type { PluginMetadata } from '@/plugins/plugin' | ||
import { getJson, getJsonWithCredentials } from '@/core/ajax' | ||
import { createLinkAction, matchInput } from '../common' | ||
|
||
export const plugin: PluginMetadata = { | ||
name: 'launchBar.actions.numberSearch', | ||
displayName: '搜索栏 - 数字联想', | ||
async setup({ addData }) { | ||
addData('launchBar.actions', (providers: LaunchBarActionProvider[]) => { | ||
providers.push({ | ||
name: 'numberSearchProvider', | ||
getActions: async input => { | ||
const { match, id, indexer } = matchInput(input, /^()(\d+)$/) | ||
if (!match) { | ||
return [] | ||
} | ||
const [aidJson, cvJson] = await Promise.all([ | ||
await getJsonWithCredentials(`https://api.bilibili.com/x/web-interface/view?aid=${id}`), | ||
await getJson(`https://api.bilibili.com/x/article/viewinfo?id=${id}`), | ||
]) | ||
const { title: videoName } = lodash.get(aidJson, 'data', {}) | ||
const { title: articleName } = lodash.get(cvJson, 'data', {}) | ||
return [ | ||
createLinkAction({ | ||
name: videoName, | ||
description: '视频跳转', | ||
link: `https://www.bilibili.com/av${id}`, | ||
indexer, | ||
}), | ||
createLinkAction({ | ||
name: articleName, | ||
description: '专栏跳转', | ||
link: `https://www.bilibili.com/read/cv${id}`, | ||
indexer, | ||
}), | ||
] | ||
}, | ||
}) | ||
}) | ||
}, | ||
} |