Skip to content

Scripts Overview

Userscripts let you extend Super Clipboard with menu commands, listeners, panels, and KV storage — all in plain JavaScript / TypeScript.

Design principles

PrincipleWhat it means
Tampermonkey-styleFamiliar // ==UserScript== metadata header
Two grants onlyutools.* and globalNativeApi.* — minimal surface
SandboxedEach script runs in its own iframe with sandbox="allow-scripts allow-downloads"
Async by defaultAll native calls go through a postMessage bridge → Promise
Type-safeShip @super-clipboard/userscript-types and get full IntelliSense + Twoslash

Runtime model

text
┌────────────── plugin window (host) ──────────────┐
│                                                  │
│  history list / settings / panel host            │
│                                                  │
│  ┌────────────────────────────────────────────┐  │
│  │  iframe  (script "foo")                    │  │
│  │   ├── globalNativeApi.* ─┐                 │  │
│  │   └── utools.* (subset) ─┤  postMessage   │──┼──► host bridge
│  │                          │                 │  │
│  └────────────────────────────────────────────┘  │
│                                                  │
└──────────────────────────────────────────────────┘
  • One iframe per script; the iframe persists across closePanel() so state (in-memory, IndexedDB) is retained.
  • The host enforces grants, namespace isolation, and timeouts (@timeout).

Injected globals

GlobalProvided when
globalNativeApialways (no grant needed for info, log, warn, error)
utoolsonly if @grant utools.*

The full surface of utools is the public uTools API minus a denylist (see Grants & Sandbox).

Lifecycle

EventTrigger
parsePlugin starts → metadata header validated
instantiateiframe created; script source injected
readyFirst registerMenuCommand / listener call
commandUser invokes a menu command
disposeUser disables / uninstalls / @timeout exceeded

Background scripts (@run-at background) are instantiated as soon as the plugin starts, regardless of UI visibility.

Built-in scripts

Shipped with the plugin and re-installed when the bundled script set is upgraded:

IDWhat it does
qr-codeGenerate a QR code image from a text clip
tokenizeTokenize text (Chinese / mixed) and show counts
save-asSave image / file clip to a chosen path

Where next