OneScript

外部输入

读取 OneScript 分享操作传入的文本、URL、文件和图片。

从 onescript/input 导入 input,读取分享面板操作传入的内容。

import { input } from "onescript/input"

for (const item of input.items) {
  if (item.type === "text" || item.type === "url") {
    console.log(item.value)
  } else {
    console.log(item.name, item.path, item.contentType)
  }
}

input.items 是按宿主 App 原始顺序排列的只读数组。脚本没有外部输入时,该数组为空。

文件和图片包含临时本地路径。脚本可以通过 node:fs 读取这些路径。执行结束后,临时文件会被清理。

Action 入口

OneScript 分享操作与首页项目卡片运行同一个 App 入口:项目根目录 config.json 中的 entries.app,其值为 package.json 中的脚本名。可以在项目的“更多设置”中修改,也可以直接编辑该文件。

{
  "entries": {
    "app": "app"
  }
}

未配置 App 入口时,依次使用 package.main、index.js、index.ts。配置的脚本不在 package.json 中,或对应文件不存在时,分享操作会报错,不会回退。

OneScript 在分享面板注册一个固定操作。打开后会动态显示当前项目,因此新建或改名后的项目会直接出现在列表中。

How is this guide?

最后更新于

本页目录