diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2023-03-16 11:56:20 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2023-03-16 11:56:20 +0900 |
| commit | 925cc06aea4aea0bed4624df82bc84c6ca4a98a0 (patch) | |
| tree | 0e8407982ce378f0482d6476fc51bb2b06b6ab9a /packages/frontend/src/scripts | |
| parent | enhance(client): update AiScript to 0.13.0 (diff) | |
| download | sharkey-925cc06aea4aea0bed4624df82bc84c6ca4a98a0.tar.gz sharkey-925cc06aea4aea0bed4624df82bc84c6ca4a98a0.tar.bz2 sharkey-925cc06aea4aea0bed4624df82bc84c6ca4a98a0.zip | |
enhance(client): tweak search page
Diffstat (limited to 'packages/frontend/src/scripts')
| -rw-r--r-- | packages/frontend/src/scripts/lookup.ts | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/packages/frontend/src/scripts/lookup.ts b/packages/frontend/src/scripts/lookup.ts new file mode 100644 index 0000000000..ce5b03fc38 --- /dev/null +++ b/packages/frontend/src/scripts/lookup.ts @@ -0,0 +1,41 @@ +import * as os from '@/os'; +import { i18n } from '@/i18n'; +import { mainRouter } from '@/router'; +import { Router } from '@/nirax'; + +export async function lookup(router?: Router) { + const _router = router ?? mainRouter; + + const { canceled, result: query } = await os.inputText({ + title: i18n.ts.lookup, + }); + if (canceled) return; + + if (query.startsWith('@') && !query.includes(' ')) { + _router.push(`/${query}`); + return; + } + + if (query.startsWith('#')) { + _router.push(`/tags/${encodeURIComponent(query.substr(1))}`); + return; + } + + if (query.startsWith('https://')) { + const promise = os.api('ap/show', { + uri: query, + }); + + os.promiseDialog(promise, null, null, i18n.ts.fetchingAsApObject); + + const res = await promise; + + if (res.type === 'User') { + _router.push(`/@${res.object.username}@${res.object.host}`); + } else if (res.type === 'Note') { + _router.push(`/notes/${res.object.id}`); + } + + return; + } +} |