Skip to content

Widget.dom

Anything that comes from a viewer (their name, their message) may contain HTML. Widget.dom draws it as text, never as code.

Widget.dom.text(element, value): Element

Sets value with textContent (never HTML) and returns the element.

Widget.dom.renderMessage(parts): DocumentFragment

A message with its emotes as images and the rest as text, ready for append. It takes message.parts from a chat event (or plain text).

Widget.on("Twitch.ChatMessage", (message) => {
item.append(Widget.dom.renderMessage(message.parts));
});
Widget.dom.image(url, options?): HTMLImageElement | null

An <img> only if the URL is from an allowed CDN (emotes, badges, cheers); otherwise null. options accepts alt and className.