Add hook for the Token configuration of the image source

This commit is contained in:
Oliver 2026-02-01 16:05:57 -07:00
parent 7777967fcc
commit 516c0d0c5e
2 changed files with 26 additions and 0 deletions

View file

@ -0,0 +1,25 @@
import { ArtBrowser } from "../apps/ArtBrowser.mjs";
/*
This hook handles adding the button for selecting an image using this module
into the prototype token config and the token-specific config. Handling both
apps with a single hook.
*/
Hooks.on(`renderTokenApplication`, (app, form) => {
// Locate where we want to inject the button
/** @type {HTMLElement | undefined} */
const picker = form.querySelector(`file-picker[name="texture.src"]`);
if (!picker) { return };
// Create the button and listener
const button = document.createElement(`button`);
button.type = `button`;
button.classList = `icon fa-solid fa-paintbrush`;
button.addEventListener(`click`, async () => {
const src = await ArtBrowser.select(1);
picker.value = src;
});
// Inject the element into the DOM
picker.insertAdjacentElement(`afterend`, button);
});