Example: night-theme
What ships is the extension/ folder: manifest.json and main.js. The test sits beside it, outside the package. Back to all examples.
extension/manifest.json
{
"id": "com.example.night-theme",
"name": "Midnight Ink Theme",
"version": "1.0.0",
"entry": "main.js",
"description": "Offers a dark blue theme. Nothing changes until you pick it under the extension in Settings > Extensions.",
"permissions": ["ui.theme", "ui.command"],
"author": { "name": "Example Author", "key": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" }
}
extension/main.js
// @ts-check
/// <reference types="@rin-chat/extension-api" />
// Midnight Ink Theme: rin.ui.theme only OFFERS a theme. It appears under the extension in Settings >
// Extensions, and nothing changes until the user presses Use there; it is then saved as one of the user's
// own themes. Values are hex colors for the Theme & Colors tokens; no CSS is involved.
/** @type {import("@rin-chat/extension-api").Theme} */
const THEME = {
name: "Midnight Ink",
mode: "dark",
colors: {
"--bg": "#0e1116",
"--bg-alt": "#12161d",
"--surface": "#171c24",
"--surface-2": "#1e2430",
"--reply-bg": "#151a22",
"--border": "#2a3140",
"--foreground": "#e6e9ef",
"--muted": "#9aa3b2",
"--purple": "#8b7cf6",
"--purple-light": "#b3a8ff",
},
chat: { quoteColor: "#c9b8ff", italicColor: "#a8b3c7" },
};
// Offering again replaces the earlier offer, so doing it on every open is harmless.
rin.on("onChatOpen", async () => {
await rin.ui.theme(THEME);
});
rin.ui.command("nighttheme", "Withdraw the Midnight Ink offer with: /nighttheme off");
rin.on("onCommand", async ({ name, args }) => {
if (name !== "nighttheme") return;
await rin.ui.theme(args === "off" ? null : THEME);
});
night-theme.test.mjs
Run it from the example's folder: rinext test extension night-theme.test.mjs.
// rinext test extension night-theme.test.mjs
import assert from "node:assert/strict";
export async function offersTheThemeWhenAChatOpens({ open, p6b }) {
const chat = await open();
// A theme that failed the shape or contrast check would have rejected, and the hook would be in chat.errors.
assert.deepEqual(chat.errors, []);
assert.equal(p6b.themes.length, 1);
assert.equal(p6b.themes[0].name, "Midnight Ink");
assert.equal(p6b.themes[0].mode, "dark");
}
export async function theCommandWithdrawsIt({ open, p6b }) {
const chat = await open();
await chat.command("/nighttheme off");
assert.equal(p6b.themes.at(-1), null);
}