modscode EN

modscode / 図鑑 / ptt

ptt

在 Claude Code 面板裡滑 PTT,可自訂看板,附老闆鍵

確かめやすいコードターミナル+デスクトップペインBoxButtonInputMarkdownText

何をするか

  • 欄を描く
  • /ptt を足す
  • session.startにフックする
  • ターンをまたいで自分の状態を持つ
  • ネットワークに出る

良いところ

  • プロセスを起こさない
  • TypeScript で書かれている
  • ファイルを書かない

作り始めるためのコード

2 種類あります。上のデザインから modscode が書いた雛形と、その Mod 自身のコードのうち描いている部分です。

雛形(register.tsx)

register.tsx
import type { Register } from 'claude-code'

// Drawn like ptt by chenyao0910 (pane), as modscode read it from the mod's code:
// https://modscode.com/gallery/chenyao0910-ptt/
// Written by modscode from that reading, not copied from the mod: use it as you like.
// Each value below stands for one the mod works out at run time; put in your own.
export const register: Register = on => {
  // the pane: open it with $.ui.open({ id: 'my-pane', title: "PTT" })
  on('ui.render', { component: 'Pane', requestId: 'my-pane' }, async ($, e) => {
    const { Box, Text, Button, Markdown } = $.ui.resolve(e)
    const name = '…'
    const b = '…'
    const b2 = '…'
    const b3 = '…'
    const msg = '…'
    const prefix = '…'
    const tag = '…'
    const rest = '…'
    const author = '…'
    const date = '…'
    const prefix2 = '…'
    const author2 = '…'
    const date2 = '…'
    const prefix3 = '…'
    const author3 = '…'
    const date3 = '…'
    return (
      <Box flexDirection="column" gap={1}>
        <Box flexDirection="row" columnGap={1}>
          <Text backgroundColor="blue" color="white" bold>
            {" PTT "}
          </Text>
          <Text dimColor>
            批踢踢實業坊 ›
          </Text>
          <Text color="yellow" bold>
            {`${name} › 文章`}
          </Text>
        </Box>
        <Box flexDirection="column">
          <Box flexDirection="row" flexWrap="wrap" columnGap={1}>
            <Text color="cyan" bold>
              看板
            </Text>
            <Text dimColor>
              |
            </Text>
            <Button variant="primary" plain label={`${b}`} />
            <Text dimColor>
              |
            </Text>
            <Button variant="primary" plain label={`${b}`} />
            <Text dimColor>
              |
            </Text>
            <Button variant="primary" plain label={`${b}`} />
          </Box>
          <Text color="blue" dimColor>
            ────────
          </Text>
          <Box flexDirection="row" flexWrap="wrap" columnGap={1}>
            <Text color="magenta" bold>
              操作
            </Text>
            <Button hotkey="r" variant="secondary" label="重新整理" />
            <Button hotkey="e" variant="primary" label="完成" />
            <Button hotkey="b" variant="secondary" label="老闆鍵" />
          </Box>
        </Box>
        <Box flexDirection="column" borderStyle="round" borderColor="cyan" paddingX={1}>
          <Text color="cyan" bold>
            管理看板
          </Text>
          <Text dimColor>
            清單是空的,新增一個看板吧
          </Text>
          <Box flexDirection="row" columnGap={1}>
            <Text color="yellow">
              {b}
            </Text>
            <Button plain label="✕ 移除" />
          </Box>
          <Box flexDirection="row" columnGap={1}>
            <Text color="yellow">
              {b2}
            </Text>
            <Button plain label="✕ 移除" />
          </Box>
          <Box flexDirection="row" columnGap={1}>
            <Text color="yellow">
              {b3}
            </Text>
            <Button plain label="✕ 移除" />
          </Box>
          <Text dimColor>
            新增看板:輸入 /ptt add 看板名稱
          </Text>
          <Button plain dimColor label="恢復預設看板" />
        </Box>
        <Text>
          {msg}
        </Text>
        <Box flexDirection="column">
          <Markdown text="_還沒載入,按上面的看板或「重新整理」_" />
          <Box flexDirection="row" columnGap={1}>
            <Text bold>
              {"  "}
            </Text>
            <Text dimColor>
              {prefix}
            </Text>
            <Text>
              {`[${tag}]`}
            </Text>
            <Button plain label={`${rest}`} />
            <Text color="cyan" dimColor wrap="truncate">
              {author}
            </Text>
            <Text dimColor>
              {date}
            </Text>
          </Box>
          <Box flexDirection="row" columnGap={1}>
            <Text bold>
              {"  "}
            </Text>
            <Text dimColor>
              {prefix2}
            </Text>
            <Text>
              {`[${tag}]`}
            </Text>
            <Button plain label={`${rest}`} />
            <Text color="cyan" dimColor wrap="truncate">
              {author2}
            </Text>
            <Text dimColor>
              {date2}
            </Text>
          </Box>
          <Box flexDirection="row" columnGap={1}>
            <Text bold>
              {"  "}
            </Text>
            <Text dimColor>
              {prefix3}
            </Text>
            <Text>
              {`[${tag}]`}
            </Text>
            <Button plain label={`${rest}`} />
            <Text color="cyan" dimColor wrap="truncate">
              {author3}
            </Text>
            <Text dimColor>
              {date3}
            </Text>
          </Box>
        </Box>
        <Button hotkey="n" variant="secondary" label="載入更舊的文章" />
      </Box>
    )
  })
}

Mod 自身のコード

Mod のライセンス(MIT)に従って載せています。全文は下にあります。写すときは著作権表示を残してください。

plugins/ptt/hooks/register.tsx 194〜353 行 · ペイン
  on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e) => {
    const ui = $.ui.resolve(e)
    const { Box, Text, Button, Markdown } = ui
    const m = await read($, mode)
    const msg = await read($, status)

    if (m === 'boss') {
      return (
        <Box flexDirection="column">
          {FAKE_LOG.map(line => (
            <Text dimColor={line.startsWith('[debug]')} color={line.startsWith('[warn]') ? 'yellow' : undefined}>
              {line}
            </Text>
          ))}
          <Button key="boss" plain dimColor hotkey="b" label="_" onPress={() => void toggleBoss($)} />
        </Box>
      )
    }

    const name = await read($, board)
    const list = await read($, boards)
    const isEditing = await read($, editing)
    const width = Math.max(20, Math.min(e.props.bodyColumns, 100))
    const divider = <Text color="blue" dimColor>{'─'.repeat(width)}</Text>

    const header = (
      <Box key="header" flexDirection="row" columnGap={1}>
        <Text backgroundColor="blue" color="white" bold>{' PTT '}</Text>
        <Text dimColor>批踢踢實業坊 ›</Text>
        <Text color="yellow" bold>{m === 'article' ? `${name} › 文章` : name}</Text>
      </Box>
    )

    const statusLine = msg !== '' && <Text color={statusColor(msg)}>{msg}</Text>

    if (m === 'article') {
      const a = await read($, article)
      if (a) {
        const good = a.pushes.filter(p => p.tag.startsWith('推')).length
        const bad = a.pushes.filter(p => p.tag.startsWith('噓')).length
        const body = a.body.length > MAX_BODY ? `${a.body.slice(0, MAX_BODY)}\n…(內文太長,後面省略)` : a.body
        const shown = a.pushes.slice(-MAX_PUSHES)
        const t = splitTitle(a.title)
        return (
          <Box flexDirection="column" gap={1}>
            {header}
            <Box key="nav" flexDirection="row" columnGap={1}>
              <Button key="back" hotkey="h" variant="primary" label="← 回列表" onPress={() => void update($, mode, () => 'list')} />
              <Button key="boss" hotkey="b" variant="secondary" label="老闆鍵" onPress={() => void toggleBoss($)} />
            </Box>
            <Box key="head" flexDirection="column" borderStyle="round" borderColor="blue" paddingX={1}>
              <Box key="title-row" flexDirection="row" columnGap={1}>
                {t.prefix !== '' && <Text dimColor>{t.prefix}</Text>}
                {t.tag !== '' && <Text color={tagColor(t.tag)} bold>{`[${t.tag}]`}</Text>}
                <Text bold>{t.rest}</Text>
              </Box>
              <Box key="meta-row" flexDirection="row" columnGap={1}>
                <Text dimColor>作者</Text>
                <Text color="cyan">{a.author}</Text>
                <Text dimColor>{`· ${a.time}`}</Text>
              </Box>
            </Box>
            <Text wrap="wrap">{body}</Text>
            {divider}
            <Box key="score" flexDirection="row" columnGap={1}>
              <Text color="green" bold>{`推 ${good}`}</Text>
              <Text color="red" bold>{`噓 ${bad}`}</Text>
              <Text dimColor>{`共 ${a.pushes.length} 則${shown.length < a.pushes.length ? `(只顯示最後 ${shown.length} 則)` : ''}`}</Text>
            </Box>
            <Box key="pushes" flexDirection="column">
              {shown.map((p, i) => (
                <Box key={`push${i}`} flexDirection="row" columnGap={1}>
                  <Text color={pushColor(p.tag)} bold>{p.tag}</Text>
                  <Text color="yellow">{p.user}</Text>
                  <Text wrap="wrap">{p.text}</Text>
                  <Text dimColor>{p.time}</Text>
                </Box>
              ))}
            </Box>
          </Box>
        )
      }
    }

    // 看板一列、操作一列,中間用線分開
    const boardRow = (
      <Box key="boards" flexDirection="row" flexWrap="wrap" columnGap={1}>
        <Text color="cyan" bold>看板</Text>
        {list.flatMap((b, i) => [
          ...(i > 0 ? [<Text dimColor>|</Text>] : []),
          <Button
            key={`board-${b}`}
            variant={b === name ? 'primary' : undefined}
            plain={b === name ? undefined : true}
            label={b}
            onPress={() => void loadBoard($, b)}
          />,
        ])}
      </Box>
    )
    const actionRow = (
      <Box key="actions" flexDirection="row" flexWrap="wrap" columnGap={1}>
        <Text color="magenta" bold>操作</Text>
        <Button key="refresh" hotkey="r" variant="secondary" label="重新整理" onPress={() => void loadBoard($, name)} />
        <Button key="edit" hotkey="e" variant={isEditing ? 'primary' : 'secondary'} label={isEditing ? '完成' : '管理看板'} onPress={() => void update($, editing, v => !v)} />
        <Button key="boss" hotkey="b" variant="secondary" label="老闆鍵" onPress={() => void toggleBoss($)} />
      </Box>
    )

    const manage = isEditing && (
      <Box key="manage" flexDirection="column" borderStyle="round" borderColor="cyan" paddingX={1}>
        <Text color="cyan" bold>管理看板</Text>
        {list.length === 0 && <Text dimColor>清單是空的,新增一個看板吧</Text>}
        {list.map(b => (
          <Box key={`row-${b}`} flexDirection="row" columnGap={1}>
            <Text color="yellow">{b}</Text>
            <Button key={`remove-${b}`} plain label="✕ 移除" hover={{ color: 'red', bold: true }} onPress={() => void removeBoard($, b)} />
          </Box>
        ))}
        {'Input' in ui ? (
          <ui.Input key="add-board" label="新增看板" placeholder="輸入看板英文名稱,例如 NBA,按 Enter" onSubmit={(v: string) => void addBoard($, v)} />
        ) : (
          <Text dimColor>新增看板:輸入 /ptt add 看板名稱</Text>
        )}
        <Button key="reset" plain dimColor label="恢復預設看板" onPress={() => void resetBoards($)} />
      </Box>
    )

    const items = await read($, posts)
    const older = await read($, prevPage)
    return (
      <Box flexDirection="column" gap={1}>
        {header}
        <Box key="controls" flexDirection="column">
          {boardRow}
          {divider}
          {actionRow}
        </Box>
        {manage}
        {statusLine}
        <Box key="list" flexDirection="column">
          {items.length === 0 && msg === '' && <Markdown key="empty" text="_還沒載入,按上面的看板或「重新整理」_" />}
          {items.map(p => {
            const t = splitTitle(p.title)
            return (
              <Box key={p.url} flexDirection="row" columnGap={1}>
                <Text color={nrecColor(p.nrec)} bold>{p.nrec.padStart(2, ' ') || '  '}</Text>
                {t.prefix !== '' && <Text dimColor>{t.prefix}</Text>}
                {t.tag !== '' && <Text color={tagColor(t.tag)}>{`[${t.tag}]`}</Text>}
                <Button key={`open-${p.url}`} plain label={t.rest} hover={{ color: 'cyan', bold: true }} onPress={() => void openArticle($, p.url)} />
                <Text color="cyan" dimColor wrap="truncate">{p.author}</Text>
                <Text dimColor>{p.date}</Text>
              </Box>
            )
          })}
        </Box>
        {older !== '' && <Button key="older" hotkey="n" variant="secondary" label="載入更舊的文章" onPress={() => void loadBoard($, name, older)} />}
      </Box>
    )
  })
ライセンスの全文(MIT)
MIT License

Copyright (c) 2026 chenyao0910

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

コードが呼ぶもの

通信保存

コードから読み取ったデザイン

読み取ったコミットのソースから描いたもので、動かした結果ではありません。一覧は 3 回描き、条件はデスクトップアプリで描く最初の分岐を取り、動かしたときにだけ決まる値は仮の例(点線の下線)にするか省きます。色と書体はこのサイトのものです。

コードから読めること

2026-10-06 に読んだコミット 0b13fdd72b6c のソースから。最初のまとまりが載せる条件で、残りは自分で判断するための材料です。後のコミットは、次に読むまで見ていません。

載せる条件: 確かめやすいコード
入口を読んだhooks/hooks.json が名指すモジュールをすべて読んだ。plugins/ptt/hooks/register.tsx
解析できるすべてのファイルが TypeScript か JavaScript として解析できる。2 ファイルを解析
コードが Mod の中で完結import は Mod 自身のファイルかエンジンのモジュールだけ。パッケージも require もない。コードはすべて Mod の中
読める圧縮した行・eval・new Function・計算した道の import()・符号化した塊がない。圧縮・eval・符号化した塊なし
呼び出しが見える通信とプログラム起動はその場で $.http.fetch・$.process.run と書き、他へ渡さない。外への呼び出しはすべてその場の $ で
入れる前に自分で判断する材料
描く場所コードから読んだ、描く先。ターミナル・デスクトップアプリ・両方・何も描かない(フックだけ: 見張りやプロンプトの書き換え)のどれか。出すだけで、外す理由にはしない。ターミナルとデスクトップアプリに同じように描く
入れる手順リポジトリ自身の .claude-plugin/marketplace.json にこの Mod が載っていて、ページに書いた手順でそのマーケットプレイスから入れられるか。リポジトリの .claude-plugin/marketplace.json に載っており、そこから入れられる
Windows のプログラム$.process で起動するプログラムが Windows にあるか(tail・date・open・osascript・/usr/… などは無い)。Windows にないプログラムを使わない
通信fetch の送り先(https のホスト)がコードに書いてあるか。plugins/ptt/hooks/register.tsx:29 fetch(HOST + path); plugins/ptt/hooks/register.tsx:87 fetch(`${HOST}/bbs/${name}/index.html`)
プログラム起動するプログラムの名前がコードに書いてあり、シェル・インタプリタ・通信用の道具でないか。プログラムを起動しない
読んで送るファイルや環境変数を読み、かつ通信するか。通信するが、ファイルも環境変数も読まない
ソースの鍵ソースに API キーや秘密鍵らしきものがあるか。ソースに鍵なし
ライセンスオープンなライセンス(MIT・Apache-2.0・BSD・ISC・Unlicense・0BSD・CC0)で全文があれば、modscode にコードを載せる。違えばリンクだけ。MIT

コードの文面を読んだだけで、安全の審査ではありません。動かしてはおらず、起動するプログラムの中で何が起きるかも見えません。入れる前の確認はあなたの役目です。 載せる条件

入れる

入れる前に、必ず自分で確かめてください。Mod はサンドボックスなしで、あなたの権限で動きます。modscode はこのコードの安全を保証しません。下のコードを読み(またはフォルダーで claude plugin validate .)、触るものを見て、読んだコミットを入れてください。

リポジトリがそのままマーケットプレイスです。このマーケットプレイスを足し(ターミナルでは次のコマンド、デスクトップアプリではプラグインの設定)、そこから Mod を入れます。

/plugin marketplace add chenyao0910/claude-ptt-mod
/plugin install ptt@claude-ptt-mod

入るのはマーケットプレイスの最新のコミットで、ここで読んだもの(0b13fdd72b6c)と違うことがあります。入れる前に見比べてください。

Claude に聞く

modscode のコネクタを入れると、Claude がこのデザイン・コードが触るもの・コードを読んで、それをもとに作れます。たとえば:

modscode のデザイン「chenyao0910-ptt」をコードごと読んで、同じようなペインを作って

Claude から探す: MCP コネクタ

似たデザイン