Getting Started
tip
Need a project to put this in first? Project Setup covers the template, the bundler, and where the built file goes.
You create every script module 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 that declares the module's options. See Options.setup: a function that wires up listeners for one session.
Here's 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 difference matters.
- The Context: everything
ctxcan do, and when listeners fire.
Next
- Modules: the
metaobject in full. - Options: the schema, with every option kind, nesting, and modes.
- Events & Packets: the full event and packet maps.