From 516c0d0c5e87ea67361be218fea504651eb03041 Mon Sep 17 00:00:00 2001 From: Oliver Date: Sun, 1 Feb 2026 16:05:57 -0700 Subject: [PATCH] Add hook for the Token configuration of the image source --- module/hooks/renderTokenApplication.mjs | 25 +++++++++++++++++++++++++ module/image-tagger.mjs | 1 + 2 files changed, 26 insertions(+) create mode 100644 module/hooks/renderTokenApplication.mjs diff --git a/module/hooks/renderTokenApplication.mjs b/module/hooks/renderTokenApplication.mjs new file mode 100644 index 0000000..556a800 --- /dev/null +++ b/module/hooks/renderTokenApplication.mjs @@ -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); +}); diff --git a/module/image-tagger.mjs b/module/image-tagger.mjs index cb60dce..a797542 100644 --- a/module/image-tagger.mjs +++ b/module/image-tagger.mjs @@ -1,2 +1,3 @@ import "./hooks/init.mjs"; import "./hooks/ready.mjs"; +import "./hooks/renderTokenApplication.mjs";