Skip to content

For Module Authors

dxcufgb edited this page Nov 5, 2026 · 2 revisions

For module authors

There is no API and no hooks to call: the menu is built from the Token HUD itself. A button you add to the Token HUD shows up in the menu by itself, and it still gets the clicks.

Hooks.on("renderTokenHUD", (hud, html) => {
  const button = document.createElement("button");
  button.type = "button";
  button.className = "control-icon";              // must be a .control-icon in one of the HUD's .col columns
  button.dataset.tooltip = "Light a torch";       // the menu entry's text
  button.innerHTML = '<i class="fa-solid fa-fire"></i>';
  button.addEventListener("click", () => { /* … */ });
  button.addEventListener("contextmenu", () => { /* right-click on the menu entry */ });
  html.querySelector(".col.right")?.append(button);
});

How a button becomes an entry

  • Text: the button's data-tooltip-text, else data-tooltip (localization keys work), aria-label, title, alt, its own text, or its data-action ("toggleTorch" → "Toggle Torch").
  • Icon: a copy of the img, svg or i inside the button (or its own fa- classes).
  • Clicks: the original button stays in the HUD, only hidden, and the menu dispatches click (left-click) or contextmenu (right-click) on it. Use those events (or the HUD's data-action handlers), not hover.
  • State: the active class on the button highlights the entry; toggle it and the menu follows. A button with the hidden attribute or style.display = "none" gets no entry.
  • Sub-menus: a button with data-palette="key" opens the HUD element .palette[data-palette="key"] as a sub-menu. Its items are the [data-action], [data-status-id], .effect-control and .control-icon elements in it; items with data-status-id are toggled with actor.toggleStatusEffect(id, { overlay }) instead of clicked. More than 12 items get a filter box.
  • Timing: buttons added or removed after the HUD rendered are picked up too (the menu watches the columns).
  • Entries come in the order of the HUD's buttons, followed by the entries for the optional modules. The players' menu on tokens they don't own shows no HUD buttons.

What it uses from the optional modules

Changing these breaks the entries:

  • Dxcufgb's lively tokens (dxcufgbs-lively-tokens): api.open(), its playersCanUse setting, and it hides its .dxlt-hud button.
  • Dxcufgb's damage dice trails (dxcufgbs-dice-trails): api.open().
  • Dxcufgb's token follower (dxcufgbs-token-follower): api.follow(follower, leader), api.stop(follower) (token documents) and the token flag flags["dxcufgbs-token-follower"].leader ({ tokenId, sceneId, name }).
  • Rideable (Rideable): api.RideableFlags.isRiddenby(mount, rider) (and api.RideableFlags.TokenisRideable must exist), game.Rideable.ToggleMount(riders, mount), the token flag flags.Rideable.issetRideableFlag, in PF2e its RideableTag setting, and it hides Rideable's [data-action="mount"] button.

Clone this wiki locally