Skip to main content

Getting Started

Need a project to put this in first? Project Setup covers the template, the bundler, and where the built file goes.

Every script module is created with a single call:

import { defineModule } from "@protohax/userscript";

defineModule(meta, schema, setup);
  • meta — the module's static identity (name, mode, …). See Modules.
  • schema — a plain object declaring the module's options. See Options.
  • setup — a function that wires listeners for one session.

A complete module:

defineModule(
{ name: "Example" },
{
enabled: { type: "boolean", name: "Feature", def: true },
},
(ctx) => {
ctx.on("tick", () => {
if (ctx.options.enabled.value) doSomething(ctx);
});
},
);

In this section

  • The Two Phases — what runs once, what runs per session, and why the boundary matters.
  • The Context — everything ctx can do, and when listeners fire.

Next

  • Modules — the meta object in full.
  • Options — the schema: every option kind, nesting, and modes.
  • Events & Packets — the full event and packet maps.