Add the ArtBrowser open when using Foundry's editImage action

This commit is contained in:
Oliver 2026-02-01 16:28:29 -07:00
parent 516c0d0c5e
commit cf8c82784b
5 changed files with 47 additions and 1 deletions

View file

@ -0,0 +1,25 @@
import { ArtBrowser } from "../apps/ArtBrowser.mjs";
import { __ID__ } from "../consts.mjs";
Hooks.on(`getHeaderControlsDocumentSheetV2`, (sheet) => {
const original = sheet.options.actions.editImage;
sheet.options.actions.editImage = async (event, target) => {
if (!game.settings.get(__ID__, `openForEditImage`)) {
return original.call(sheet, event, target);
};
if (target.nodeName !== `IMG`) {
throw new Error(`The editImage action is available only for IMG elements.`);
};
const src = await ArtBrowser.select(1);
if (!src) { return };
target.src = src;
if (sheet.options.form.submitOnChange) {
const submit = new Event(`submit`, { cancelable: true });
sheet.form.dispatchEvent(submit);
};
};
});