Skip to content

Ivory

Ivory 是 Tapbots 开发的 Mastodon 客户端。Protocol Launcher 允许你生成 Ivory URL scheme 链接。

使用

有两种方式使用此库:

  • On-Demand 从子路径导入,有利于 tree-shaking 并保持包体积较小。
  • Full Import 从根包导入,写起来更方便,但会包含所有应用模块。

生产构建建议使用 On-Demand;快速脚本或演示可以使用 Full Import。

选择安装方式

按需加载
推荐使用。生产环境优化。
全量导入
使用便捷。适合快速脚本。

说明

Tapbots 将 acct 记录为账户选择器。它可以是完整的 @user@host、短格式 @user,也可以留空表示当前激活的 Ivory 账户。省略 acct 时,Protocol Launcher 会生成类似 ivory:///home 的 URL。

本模块只暴露 Ivory 官方列出的 URL 形态:tab URL、openURLstatususer_profilepostcallbackUrl 只用于官方记录的 modal action,并会序列化为官方 callback_url query 参数。

Tabs

On-Demand
ts
import { openHome, openTimeline, openMentions, openLists, openFavorites, openBookmarks, openStatistics, openProfileTab, openSearch } from 'protocol-launcher/ivory'

const homeUrl = openHome()
const timelineUrl = openTimeline({ acct: '@alice' })
const mentionsUrl = openMentions({ acct: '@alice' })
const listsUrl = openLists()
const favoritesUrl = openFavorites()
const bookmarksUrl = openBookmarks()
const statisticsUrl = openStatistics()
const profileTabUrl = openProfileTab({ acct: '@alice@mastodon.social' })
const searchUrl = openSearch()

打开 URL

On-Demand
ts
import { openUrl } from 'protocol-launcher/ivory'

const url = openUrl({
  acct: '@alice@mastodon.social',
  url: 'https://mastodon.social/@tapbots',
  callbackUrl: 'launcher://done',
})

打开 Status

On-Demand
ts
import { openStatus } from 'protocol-launcher/ivory'

const url = openStatus({
  acct: '@alice@mastodon.social',
  statusId: '110123456789',
})

打开 Profile

On-Demand
ts
import { openProfile } from 'protocol-launcher/ivory'

const url = openProfile({
  acct: '@alice@mastodon.social',
  userAcct: '@tapbots@mastodon.social',
})

Compose

On-Demand
ts
import { compose } from 'protocol-launcher/ivory'

const url = compose({
  acct: '@alice',
  callbackUrl: 'launcher://done',
})

Compose Text Path

On-Demand
ts
import { composeText } from 'protocol-launcher/ivory'

const url = composeText({
  acct: '@alice',
  text: 'Hello Ivory',
})

Compose Reply

On-Demand
ts
import { composeReply } from 'protocol-launcher/ivory'

const url = composeReply({
  acct: '@alice',
  text: 'Hello Ivory',
  inReplyToStatusUrl: 'https://mastodon.social/@tapbots/110123456789',
})

生成的 URL

ts
openHome()
// => 'ivory:///home'

openTimeline({ acct: '@alice' })
// => 'ivory://@alice/timeline'

openUrl({
  acct: '@alice@mastodon.social',
  url: 'https://mastodon.social/@tapbots',
  callbackUrl: 'launcher://done',
})
// => 'ivory://@alice@mastodon.social/openURL?url=https%3A%2F%2Fmastodon.social%2F%40tapbots&callback_url=launcher%3A%2F%2Fdone'

openStatus({
  acct: '@alice@mastodon.social',
  statusId: '110123456789',
})
// => 'ivory://@alice@mastodon.social/status/110123456789'

openProfile({
  acct: '@alice@mastodon.social',
  userAcct: '@tapbots@mastodon.social',
})
// => 'ivory://@alice@mastodon.social/user_profile/@tapbots@mastodon.social'

compose()
// => 'ivory:///post'

compose({
  acct: '@alice',
  callbackUrl: 'launcher://done',
})
// => 'ivory://@alice/post?callback_url=launcher%3A%2F%2Fdone'

composeText({
  acct: '@alice',
  text: 'Hello Ivory',
})
// => 'ivory://@alice/post/Hello%20Ivory'

composeReply({
  acct: '@alice',
  text: 'Hello Ivory',
  inReplyToStatusUrl: 'https://mastodon.social/@tapbots/110123456789',
})
// => 'ivory://@alice/post?text=Hello%20Ivory&in_reply_to_status_url=https%3A%2F%2Fmastodon.social%2F%40tapbots%2F110123456789'

官方文档