JLERTS CUSTOM ALERTS, WIDGETS AND CHAT OVERLAYS: THE GUIDE FOR AI ASSISTANTS
https://jlerts.com/docs/widget-api.txt · For people: https://jlerts.com/docs/build-widgets
Jlerts is a free Windows app for Twitch alerts, widgets and chat overlays that streamers show in OBS. A custom widget
is a small web page in a folder. You (the AI) write the files; the streamer zips the folder and imports it in Jlerts.
Write plain HTML, CSS and JavaScript (no build step, no frameworks needed). Follow every rule below.
PICK THE TYPE FIRST. Custom alerts, widgets and chat overlays are all built this way; widget.json "type" says which:
- The streamer asks for an alert (it plays when someone follows, subs, raids, cheers, tips...)
-> "type": "alert", plus "duration" in seconds, and show it from widget.on("play", ...)
- Something that stays on screen (goal bar, list, counter, timer, pet, latest events)
-> "type": "widget"
- A chat box or chat overlay
-> "type": "chat"
If "type" is missing it becomes a widget, and the import lands in the wrong tab. When the streamer says "alert", it is
always "type": "alert", even if they also call it a widget.
1. THE FOLDER
-------------
my-widget/
widget.json name, type, size (required)
index.html the page (required)
style.css the look
script.js what it does
fields.json its settings, shown as a normal settings panel in the app (optional)
art/... pictures, sounds, fonts it uses (optional)
Zip the folder's files (widget.json at the top level of the zip, or inside one folder). In Jlerts: Alerts, Widgets or
Chat tab -> the arrow next to "+ New" -> Import (.zip). It goes to the right tab by its "type".
2. widget.json
--------------
{
"name": "Thanks list", shown in the app
"type": "widget", "widget" (stays on screen, the default) | "alert" (plays on events) | "chat" (chat overlay)
"width": 520, size on the stream canvas, in pixels (1920x1080 stream)
"height": 360,
"duration": 6, alerts only: seconds it shows
"speaks": true optional: the widget may talk (see 8)
}
3. index.html
-------------
The page shows at the widget's size, see-through wherever nothing is drawn. Keep
background transparent.
Always load the API before your own script:
4. fields.json (settings)
-------------------------
An array. Each field: key, label, type, default. The values arrive as widget.settings..
[
{ "key": "title", "label": "Title", "type": "text", "default": "Thanks for the support!" },
{ "key": "note", "label": "Long text", "type": "textarea", "default": "" },
{ "key": "colour", "label": "Accent colour", "type": "colour", "default": "#8b5cf6" },
{ "key": "font", "label": "Font", "type": "font", "default": "Segoe UI" },
{ "key": "max", "label": "Names to show", "type": "number", "default": 5, "min": 1, "max": 20 },
{ "key": "chat", "label": "Wave at chat", "type": "checkbox", "default": false },
{ "key": "style", "label": "Card style", "type": "select", "default": "glass", "options": ["glass", "solid"] }
]
Types: text, textarea, colour (or color), font, number (min, max), checkbox, select (options: an array of strings),
preview (see 9), goal (a drop-down of the streamer's Jlerts goals; see 7). Values: text and select give text, number a
number, colour "#rrggbb", checkbox true / false, font the font's name for font-family, goal the goal's id ("" = none). Give every setting a sensible default so the widget works the moment it's imported.
5. THE widget OBJECT (from /custom-api.js)
-------------------------------------------
widget.settings the fields.json values, any time
widget.muted true when another copy of this page (on another overlay) is the one heard: check it
before playing any sound of your own (set from "load" on)
widget.on("load", fn) the page is ready and settings have arrived: start here
widget.on("settings", fn) fn(settings): the streamer changed a setting; redraw
widget.on("chat", fn) every chat message (see 6)
widget.on("event", fn) every event: fn({ kind, vars, amount, test })
Events about someone carry vars.avatar: their profile picture's address (their
Twitch / Kick picture, or a round first-letter picture), e.g.
widget.users.picture("name") anyone's picture address the same way ("kick:name" for Kick): leaderboards, top lists
widget.on("", fn) one kind of event, e.g. widget.on("follow", vars => ...)
widget.on("play", fn) type "alert" only: fn(vars, { kind, durationMs, test, resumed, muted }) when the
alert starts, once. kind is the event it plays for ("hypetrain_start"...); resumed is
true when OBS reloaded the page and Jlerts put the alert back (skip the big entrance);
muted is true when this copy must play no sound (another overlay plays it): check it
before playing any sound of your own
widget.done() type "alert" only: finished early (otherwise it ends after "duration")
widget.store.get(key) small things saved between streams (a count, a list of names): returns the value
widget.store.set(key, value) saves it (JSON-friendly values, 64 KB in total; bigger isn't saved)
Read widget.settings and widget.store from "load" or later: they're empty before that.
Event kinds:
follow, sub, resub, giftsub, cheer, raid, donation (tips), redeem (channel points), shoutout,
hypetrain_start, hypetrain_level, hypetrain_end, adbreak, bits_other, bitsbadge,
watchstreak (a viewer shared their Twitch watch streak: user, streamstreak = streams in a row, message;
amount = streams in a row),
powerup_custom (one of your own Bits Power-ups: user, powerup = its name, powerup_id, bits),
modiversary (a mod shared their mod anniversary: user, months, duration "1 year 3 months"),
gifteddrops (someone gifted Drops: user, count = viewers given them),
twitchgoal_new, twitchgoal_reached (one of your Twitch Goals started / was reached: description, goal_type,
current, target, progress),
powerup_gigantify, powerup_celebration (emote = the emote's name, emote_url = its picture),
powerup_effect, firstchat, newchatter, command,
gamble, slots, duel, shop, game (points games), topsupporter (user, what, amount, previous),
subathon_time (time went on the Subathon clock: user, time "+5:00", added "5 min", reason "5 gift subs", left,
seconds; amount = minutes added),
moderation: banned, timeout, unbanned (Twitch and Kick); newmod, modremoved, newvip, vipremoved, warned, shieldon,
shieldoff, automod, suspicious, chatmode, unbanrequest (Twitch). They carry user, moderator, reason, duration
(timeouts, e.g. "10 minutes"), message (automod, suspicious, unbanrequest), modes (chatmode). Custom alerts can be
linked to any of them; normal alerts to banned, timeout, unbanned, newmod and newvip (Triggers → Moderation).
Vars (not every kind has every one; values are usually text): user, login, message, platform, amount, amount_raw,
currency, bits, kicks, count (giftsub), viewers (raid), months, streak, tier, duration, total_gifts, membership, first,
new, tier_text, reward, cost, prompt, command, target, points, points_name, points_total, time, time12, date,
time_left, subathon_added, goal_name, goal_current, goal_target, goal_left, goal_percent, goal_progress,
goal_current_text, goal_target_text, goal_left_text.
Always fall back: vars.user || "Someone", Number(vars.amount) || 0.
test is true when the streamer pressed Test in the app.
HOW A CUSTOM ALERT STARTS, UPDATES AND ENDS
- A ZIP can't choose its trigger. The streamer links the alert to an event in the app (the alert's When it plays,
or the Triggers tab). Tell them which event to pick.
- play fires once, when the alert starts. While it's on screen the page keeps hearing every event
(widget.on("hypetrain_level", ...) and the rest), so update the page from those: play never fires again.
- It ends after widget.json "duration", or sooner with widget.done().
- "Last until it ends" (a tick in the alert's length settings, for hype trains and ad breaks): the alert lasts until
the train or ad break ends instead. Each newer end time keeps it on screen longer, and hypetrain_end finishes it
(it gets 5 seconds to play an outro; call widget.done() when yours is over).
- If OBS reloads the page while a train is still going, Jlerts puts the alert back: play fires with resumed: true and
the current vars (no sound replays).
HYPE TRAINS (Twitch)
Events: hypetrain_start, hypetrain_level (a new level), hypetrain_progress (more hype on the same level: the end
time moved; it never starts an alert, it only updates pages), hypetrain_end.
Vars: level, progress, goal, percent, left, total, user (top contributor), top_bits_user, top_bits, top_sub_user,
train_type, ends_at (when it ends, epoch ms), started_at (epoch ms), train_id (the same through the whole train).
await widget.hypetrain.get() the train going on now: { id, level, startedAt, expiresAt, test, vars }, or null.
expiresAt moves later with each contribution; id and startedAt never change.
Link a hype train alert to hypetrain_start only, tick "Last until it ends", and update it from inside the page (see
example E). Don't also link it to hypetrain_level.
SONG REQUESTS (Community Hub -> Song requests: !sr, played by YouTube Music Desktop or Spotify)
await widget.songRequests.get() { enabled, open, player ("pear" = YouTube Music | "spotify"),
mode ("nonstop" | "mixed"), mixSongs, requestBy ("chat" | "redeem" |
"both"), playing, line, played }. playing is the request playing now, or null while the
streamer's own playlist plays. line is what's waiting, in order (line[0] is next).
played is Played this stream, newest first.
videoId is a YouTube video's id (11 letters) or a Spotify track's (22).
Each song: { id, videoId, title, artist, seconds (its length; 0 = not known), user (who asked), platform ("twitch" |
"kick"), status ("approval" waiting for a mod's OK, "waiting", "sent" next in the player, "playing"), thumbnail }.
thumbnail is an address on the widget's own server ("/songthumb/"): use it as an src (YouTube's
own picture addresses are blocked for widgets).
widget.on("songrequests", fn) fn(same object) whenever anything changes: a request added, starting, skipped,
removed, cleared, or the settings changed. Call get() once at load too.
await widget.songRequests.skip() skips the song playing now. And
await widget.songRequests.remove(id) takes a request out of the line (its points come back). Both need the tick
"Allow this widget to skip and remove song requests" in the widget's settings
(rejects otherwise); reading never does.
Show the song's own name and artist (they come from YouTube, so long titles are common: shrink or cut them to fit).
The time left of the playing song isn't given: show its length instead.
Twitch and Kick: widgets get both. vars.platform and msg.platform are "kick" on Kick; treat anything else as Twitch. A Kick
viewer's login starts "kick:" (their own points: pass login as it is). KICKs arrive as "cheer" with vars.bits, vars.kicks
and vars.amount. Hype trains, ad breaks, Bits power-ups and Bits badges are Twitch only.
6. CHAT MESSAGES
----------------
widget.on("chat", msg => ...) gets:
msg.user display name msg.login lower-case login name
msg.text the message msg.color name colour ("#ff0000" or null)
msg.badges ["subscriber/12", "moderator/1", ...] (Twitch only)
msg.roles { broadcaster, mod, vip, sub } (true / false; use this for "mods only": it works on Kick too)
msg.platform "twitch" or "kick"
msg.fragments [{ t: "text" | "emote" | "mention" | "cheer" | "gif", text, url }] (gif: a GIF posted in Twitch chat,
url is its picture; emotes: url is the picture;
Twitch, Kick, 7TV, BetterTTV and FrankerFaceZ)
msg.bits Bits in the message, or null
msg.id, msg.userId, msg.highlighted, msg.gigantified, msg.effect, msg.replyTo, msg.replyText
msg.effect its Twitch Message Effect: "simmer" (Emote Party), "rainbow-eclipse", "cosmic-abyss", or "" (none)
msg.nickname their nickname, when the streamer uses them (optional)
msg.team { name, colour, icon, image } when teams are on (optional)
msg.squad the same shape: their squad badge (optional)
msg.pronouns, msg.avatar when known (optional)
msg.bot true when it's from a bot on the streamer's Bots list (optional): usually skip those
msg.firstTime true for someone's first message ever in the channel (optional)
msg.notice a Twitch chat notice (optional): { kind, line }, kind "sub" | "streak" | "gift" | "raid" | "announce"
| "redeem", line e.g. "resubscribed · 39 months"; msg.text is what they typed with it (can be "" for
gifts, raids and some redeems). A redeem also has reward (its name) and cost (channel points; missing on
Kick). msg.badges and msg.color are the chatter's, as on their chat messages. Show it as a notice, or
skip messages with msg.notice to keep only normal chat.
To draw emotes, build the message from msg.fragments (an for each emote). Never put msg.text into
innerHTML: use textContent, or escape it.
msg.firstTime their first message ever in your channel (Twitch's own first-time flag; on Kick,
Jlerts' own list of chatters); msg.firstThisStream: their first message this stream
widget.on("chatflag", fn) Twitch flagged a message as someone's first a moment after it came: fn({ id, firstTime })
widget.on("effect", fn) a redeem effect started (emotes over the overlay): fn({ user, redeem, kind }), kind
"float" | "drift" | "pop" | "explosion" | "rain" | "stamp" | "upward" | "fountain" | "spiral" | "conga" | "random"
(mark the message with that id)
widget.on("delete", fn) messages taken away: fn({ id }) one message (msg.id), fn({ userId }) all of someone's
(timed out or banned: msg.userId), fn({ all: true }) chat cleared. Remove them too.
7. LOYALTY POINTS AND TEAMS
---------------------------
Each returns a Promise. If it can't (points are off, not allowed...), it rejects with an Error whose message says why
in plain words. Always use try / catch.
await widget.points.info() { enabled, name, icon, notEnough } (name: what the streamer calls
their points: show it, never the word "points". notEnough: their
reply when someone hasn't got enough; the app says it by itself
when take fails for that)
await widget.points.get("login") { user, points, rank, team }
await widget.points.top(10) [{ user, points }, ...]
await widget.points.add("login", 50, "reason") give points
await widget.points.take("login", 50, "reason") take points (never below 0)
await widget.points.take("login", 50, "bet", 3500) ...and its share goes into the Vault only after 3.5 s, so the Vault
can't give a result away before your animation shows it
widget.on("points", fn) fn({ user, change, total, reason }) when points change
await widget.teams.list() { enabled, locked: "open" | "locked" | "closed",
teams: [{ name, colour, icon, image, score, members, points }] }
Rules: reading is always allowed. add / take only work when the streamer ticks "Allow this widget to change points"
in the widget's settings (with a limit per viewer, 500 to start with). take only works on someone who used the widget's
Command setting, or any !command if that's empty, in the last minute. Tell the streamer to tick that box if your widget
changes points.
Taking from someone else ("!mug @Ann"): only if the streamer also ticks "Allow it to take points from viewers named in
its command". Then take() also works on someone named (the first three words after the command, @ or not) by a viewer
who used the widget's command in the last minute, never on that viewer themselves; the per-viewer limit still applies.
Viewer values (chat games and RPGs): each viewer's own named values, kept between streams (hp, xp, level, class,
gold...). Shared with the streamer's custom commands ("Also change their values" and {stat:hp} in replies), so a !stats
command and your widget see the same numbers. Names: letters, numbers and _, up to 24 (lower case). Values: a number,
or text up to 100 characters. At most 40 per viewer. The streamer sees them on the viewer's card and can clear them.
await widget.values.get("login") { login, values: { hp: 20, xp: 150, class: "Rogue" } } ({} if none)
await widget.values.top("xp", 10) [{ user, login, value }, ...] highest first
await widget.values.set("login", { hp: 20, class: "Rogue", quest: null }) change some (null takes one away);
returns all their values
await widget.values.add("login", "xp", 10) add to a number (missing counts as 0; negative takes away): { value }
await widget.values.clear("login") take all of that viewer's values away
widget.on("values", fn) fn({ login, user, values }) when someone's values change (a command, a
widget, the streamer); fn({ all: true }) when everyone's were cleared
Rules: reading is always allowed. set / add / clear only when the streamer ticks "Allow this widget to change viewer
values" in the widget's settings. Dice are just Math.random in your code (the streamer also has a built-in !roll and
{1d20} in command replies).
The Vault (the jackpot pot):
await widget.vault.get() { enabled, amount, locked, canWin, odds, minBet, minVault, lastWin: { user, amount, game, at } or null }
widget.on("vault", fn) fn(vault) when it changes
widget.on("heist", fn) fn({ user, guess: four numbers or null, right, won, amount, line }) after a heist
await widget.vault.tryWin("login", "Display_Name", delayMs) { won: true, amount } (already paid) or { won: false }.
delayMs (up to 60000): how long its chat line and alert wait. Needs the tick "Allow this
widget to try for the Vault"; one try per play, only for someone who just typed the
command, and only after widget.points.take really took a bet of at least minBet.
Writing in chat (needs the tick "Allow this widget to write in chat"; sent from the streamer's account):
await widget.chat.say("@Ann won!") { sent: true } or { sent: false, reason }; never throws. One every 2 seconds, 20 a
minute, 300 characters, one line, no blocked words, can't start with / . or !
Goals (a goal widget showing one of the streamer's Jlerts goals; the app counts it, so it never misses events and
every scene agrees). Add { "key": "goal", "label": "Show one of your Jlerts goals", "type": "goal", "default": "" }:
await widget.goals.get(widget.settings.goal) { id, name, kind, current, target, left, percent, reached, enabled,
currentText, targetText, leftText, progress } or null
await widget.goals.list() every goal, the same shape
widget.twitchGoals.get() your Twitch Goals running now (set on Twitch): [{ id, type, description, current, target,
reached, startedAt }]; type "follower", "subscription" (sub points), "subscription_count"
(subs), "new_subscription", "new_subscription_count", "new_bit", "new_cheerer"
widget.twitchGoals.pick(which) the goals for a fields.json "twitchgoal" setting: "all", "newest" or a type
widget.on("twitchgoal", fn) they changed (started, moved on, ended): fn({ goals }); a reached one stays a few
seconds with reached: true
fields.json type "twitchgoal": the streamer picks which of their Twitch Goals ("all", "newest" or a type)
widget.playSound("chat-bloop", 80) plays one of Jlerts' own sounds by name, volume 0-100 (default 80); stays quiet
by itself on a muted copy (widget.muted), so sounds never play twice
widget.playSound(widget.settings.ding) a "sound" setting: the streamer's pick at its own volume ("" = none)
widget.sounds() every sound by group: [{ group, sounds: [{ name, label }] }]: "Chat: 8-bit bloops",
"Chat: C64 style", "Chat: 16-bit (SNES style)", "Chat: Gentle", "Chat: Soft and cute"
(names like "chat-bloop", "chat-kalimba"), then "Alerts: Retro", "Alerts: C64",
"Alerts: Chime", "Alerts: Synthwave", "Alerts: Upbeat" ("retro-follow", "chime-sub"…)
fields.json type "sound": a sound picker (a group then a sound, or their own file, and a volume):
{ "key": "ding", "label": "Sound for each message", "type": "sound", "sounds": "chat" }
("sounds": "chat" = only the chat sounds; leave it out for all). The value is
{ src, volume }: pass it straight to widget.playSound.
widget.on("goal", fn) fn(goal) when one changes: check goal.id === widget.settings.goal
await widget.goals.add(id, 5), .subtract(id, 5), .set(id, 20), .reset(id) only a goal picked in this widget's
settings; reaching the target plays the goal's alert
With a goal picked, don't count events yourself. With none (""), count with widget.store as usual.
Subathon and top supporters:
await widget.subathon.get() { enabled, on, running, paused, ended, leftMs, runMs, addedMs, capMs, at, totals: { subs,
gifts, bits, money, follows, raids, redeems }, topGifter, topCheerer, topTipper: { user,
amount } or null, challenges: [{ text, goal, target, progress, reached }], boost,
boostUntil, currency }
widget.subathon.timeLeft(clock) milliseconds left right now: call it as often as you redraw
widget.on("subathon", fn) fn(clock, change); change is { kind, user, amount, seconds, note }
await widget.subathon.add(300, "reason"), .pause(), .resume() need the tick "Allow this widget to change the Subathon"
(seconds, -3600 to 3600)
await widget.supporters.top("gifts", "stream", 5) [{ user, amount }]. "gifts" | "bits" | "tips" | "all";
"stream" | "today" | "week" | "month" | "all"
This stream's supporters, for your own ending credits (starts fresh when the streamer goes live; tests don't count):
await widget.credits.get() { raiders, subscribers, gifts, bits, tips, followers, redeems, chatters, rolling }. Each
list is [{ user, amount, text }], biggest first. amount: viewers, months, gifts, bits,
money or messages (0 for followers and redeems; a sub can be 0 too). text: only for tips
("£12.50"). chatters: the top 50. rolling: the built-in End credits are rolling now
widget.on("credits", fn) someone was added, or the built-in credits started or stopped: fn(credits), the same shape,
at most once a second (chat messages alone don't send it: call get() for fresh chatters)
8. TALKING WIDGETS (widget.json "speaks": true)
-----------------------------------------------
The streamer ticks "Allow this widget to speak" and picks the voice in the widget's settings. Don't hard-code voices.
await widget.tts.speak("Hello!") resolves { spoken: true, voice } or { spoken: false, reason }; never throws.
reasons: "not allowed", "off", "empty", "too long" (300 characters),
"too many" (6 a minute, 5 waiting), "blocked word", "stopped", "skipped",
"failed"
widget.tts.speak(text, { voice, speed, volume }) optional: voice name from voices(), speed -10..10, volume 0..1
widget.tts.stop() stops this widget's own lines
widget.tts.isSpeaking() true while one of its lines plays
await widget.tts.voices() [{ name, label, engine, language, gender }]
widget.on("tts", fn) fn({ type: "start" | "end" | "skipped", text, voice, reason })
widget.on("speech", fn) ~30 times a second while it speaks: fn({ speaking, talking, level (0-1),
beats, progress (0-1) }) (use level for a moving mouth)
Lines take turns with the app's read aloud and never play over alerts.
9. RULES (the page runs sealed off)
-----------------------------------
- No network: fetch, XMLHttpRequest, WebSockets, EventSource and beacons are blocked. Everything comes through the
widget object. Don't call Twitch or any website.
- It can load only its own files, emotes and Google Fonts. Put every picture, sound and script in the folder: anything
else from the web is blocked unless the streamer ticks "Let it load pictures, sounds and scripts from any website".
- Not allowed: iframes, workers, forms, pop-ups, downloads, opening links, localStorage, cookies. Use widget.store.
- Never put program files in the folder (.exe, .dll, .bat, .cmd, .ps1...): the import is refused. A zip can hold up to
2,000 files and 300 MB unpacked.
- Promises from the app fail with "The app didn't answer." after 10 seconds, so catch errors.
- Sounds: .mp3, .wav or .ogg in the folder, played with new Audio("sounds/cheer.mp3"). Set a.volume from a setting and
call a.play().catch(() => {}). Add a tick box to turn sounds off. In OBS, the sound comes through the browser source.
- Hearing a sound in the settings: a field { "key": "hear", "label": "Hear it", "type": "preview",
"file": "sounds/cheer.mp3", "volumeKey": "volume", "default": "" } adds a Play preview button. Only the streamer hears
it, not the stream. volumeKey (optional) is the key of a 0 to 100 number setting. Needs Jlerts build 2026.11.04.0434.
- Keep it light: it runs on a streaming PC next to a game. Prefer CSS animations; one requestAnimationFrame loop at
most; remove old elements (keep lists short).
- It must look right with no events yet (show a sensible empty state) and survive missing vars.
- OBS's browser is Chrome 127: avoid newer browser features.
10. EXAMPLES
------------
A) A widget: the last 5 supporters (type "widget").
script.js:
const list = document.getElementById("list");
let names = [];
function draw() {
list.replaceChildren(...names.slice(0, widget.settings.max || 5).map((n) => {
const li = document.createElement("li");
li.textContent = n;
return li;
}));
}
function add(line) {
names = [line, ...names].slice(0, 20);
widget.store.set("names", names);
draw();
}
widget.on("load", () => { names = widget.store.get("names") || []; draw(); });
widget.on("settings", draw);
widget.on("follow", (v) => add(`${v.user || "Someone"} followed`));
widget.on("sub", (v) => add(`${v.user || "Someone"} subscribed`));
widget.on("raid", (v) => add(`${v.user || "Someone"} raided with ${v.viewers || 0}`));
B) An alert (type "alert"): a card with the follower's name.
widget.json:
{ "name": "Follow pop-up", "type": "alert", "width": 800, "height": 300, "duration": 6 }
index.html body (plus the two script tags from section 3):
script.js:
const card = document.getElementById("card");
widget.on("play", (vars, alert) => {
document.getElementById("name").textContent = vars.user || "Someone";
document.getElementById("message").textContent = vars.message || "";
card.className = "card show";
setTimeout(() => (card.className = "card hide"), alert.durationMs - 500);
});
C) A chat overlay (type "chat").
script.js:
const box = document.getElementById("box");
widget.on("chat", (msg) => {
const row = document.createElement("div");
row.className = "msg";
const name = document.createElement("b");
name.textContent = msg.nickname || msg.user;
name.style.color = msg.color || widget.settings.colour;
row.append(name, ": ");
for (const f of msg.fragments) {
if (f.t === "emote" && f.url) {
const img = document.createElement("img");
img.src = f.url;
img.alt = f.text;
row.append(img);
} else row.append(f.text);
}
box.append(row);
while (box.children.length > 30) box.firstChild.remove();
});
D) A points game: !fish costs 10, 30% chance to win 50 (tick "Allow this widget to change points").
widget.on("chat", async (msg) => {
if (msg.text.trim().toLowerCase() !== "!fish") return;
try {
await widget.points.take(msg.login, 10, "fishing bait");
const prize = Math.random() < 0.3 ? 50 : 0;
if (prize) await widget.points.add(msg.login, prize, "caught a fish");
show(prize ? `${msg.user} caught a fish! +${prize}` : `${msg.user} got nothing...`);
} catch (err) {
show(`No fishing: ${err.message}`);
}
});
E) A hype train alert that stays up for the whole train (type "alert").
In Jlerts: link it to "Hype train started" only, and tick "Last until it ends".
widget.json:
{ "name": "Hype train", "type": "alert", "width": 700, "height": 220, "duration": 300 }
index.html body (plus the two script tags from section 3):
HYPE TRAIN level 1
script.js:
const $ = (id) => document.getElementById(id);
let endsAt = 0;
function draw(v) {
$("level").textContent = v.level || "1";
$("fill").style.width = (Number(v.percent) || 0) + "%";
if (v.ends_at) endsAt = Number(v.ends_at);
}
widget.on("play", (vars, alert) => {
draw(vars);
if (!alert.resumed) $("train").classList.add("arrive"); // the entrance only the first time
});
widget.on("hypetrain_level", (v) => { draw(v); $("train").classList.add("level-up"); });
widget.on("hypetrain_progress", draw); // same level, more time
widget.on("hypetrain_end", (v) => {
draw(v);
$("train").classList.add("leave");
setTimeout(() => widget.done(), 1500); // after the outro
});
setInterval(() => {
const s = Math.max(0, Math.round((endsAt - Date.now()) / 1000));
$("left").textContent = endsAt ? `${Math.floor(s / 60)}:${String(s % 60).padStart(2, "0")}` : "";
}, 500);
Try it: the alert's Test run button sends a whole train (start, level-ups, more time, end), and can reload the
overlay halfway to check it comes back.
11. GOOD HABITS (a widget that works on a real stream)
------------------------------------------------------
- Text: shrink it to fit its box (step the font size down until el.scrollWidth <= el.clientWidth, or scale canvas
text by maxWidth / measured width). Never cut names off with "...". Try a 25-character name (Twitch's longest).
- Chat commands: never show text a viewer typed as a name or message on stream. Only accept names of people who
chatted recently (keep a list from widget.on("chat")) and show their own display name. Add a cooldown for each
person (a setting, e.g. 30 seconds; none for msg.roles.broadcaster), skip msg.bot, and ignore the same msg.id twice.
- Several copies: the same widget can be open on more than one overlay. Base random results on msg.id (a hash), so
every copy shows the same thing. Before playing a sound of your own, check play's meta.muted (alerts) or
widget.muted (widgets and chats), so it's heard once.
- Timing: if a sound must line up with an animation, keep the animation's timing fixed in seconds rather than
stretching it to the alert's length; let a longer alert just hold the end longer.
- OBS uses an older Chrome (127): no brand-new JavaScript or CSS features. Plain, well-supported code only.
- Size: keep pictures small (resize to the size shown, compress PNGs or use WebP). Big files load slowly in OBS.
- Testing: tell the streamer to try it with Test (one event) and Test run (a series, with "Reload halfway" for
alerts that last a long time, like hype trains).
WHEN YOU ANSWER
---------------
Give every file in full, each in its own code block with its file name. Then tell the streamer, in plain words:
zip the files, import the zip in Jlerts, put it on the canvas, and which settings to change. For an alert, say which
event to link it to in its When it plays (a zip can't do that itself), and whether to tick "Last until it ends". If it uses points or a
voice, say which box to tick in the widget's settings. Use made-up names in examples, never real people.
Before you finish, check widget.json: "type" must be "alert" for an alert (with "duration"), "chat" for a chat
overlay, and "widget" for anything that stays on screen. Say which type you used and which tab it will appear in.