initial work to get the button wokring again
This commit is contained in:
parent
64e3cc4f05
commit
2c73c49b0b
2 changed files with 15 additions and 48 deletions
|
|
@ -2,7 +2,7 @@
|
||||||
"id": "duality-roller",
|
"id": "duality-roller",
|
||||||
"title": "Duality Dice Roller",
|
"title": "Duality Dice Roller",
|
||||||
"description": "Adds a button next to the chat dice/controls that triggers the /dr command for the Foundryborne Daggerheart system.",
|
"description": "Adds a button next to the chat dice/controls that triggers the /dr command for the Foundryborne Daggerheart system.",
|
||||||
"version": "0.1.3",
|
"version": "0.1.4",
|
||||||
"compatibility": {
|
"compatibility": {
|
||||||
"minimum": "13",
|
"minimum": "13",
|
||||||
"verified": "13"
|
"verified": "13"
|
||||||
|
|
@ -16,5 +16,5 @@
|
||||||
"languages": [],
|
"languages": [],
|
||||||
"url": "https://github.com/cptn-cosmo/DualityDiceRoller",
|
"url": "https://github.com/cptn-cosmo/DualityDiceRoller",
|
||||||
"manifest": "https://github.com/cptn-cosmo/DualityDiceRoller/releases/latest/download/module.json",
|
"manifest": "https://github.com/cptn-cosmo/DualityDiceRoller/releases/latest/download/module.json",
|
||||||
"download": "https://github.com/cptn-cosmo/DualityDiceRoller/releases/download/0.1.3/duality-roller.zip"
|
"download": "https://github.com/cptn-cosmo/DualityDiceRoller/releases/download/0.1.4/duality-roller.zip"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,21 +13,15 @@ Hooks.on("renderChatLog", (app, html) => addDRButton(html));
|
||||||
// Mini/Popout chat
|
// Mini/Popout chat
|
||||||
Hooks.on("renderChatPopout", (app, html) => addDRButton(html));
|
Hooks.on("renderChatPopout", (app, html) => addDRButton(html));
|
||||||
|
|
||||||
function addDRButton(html) {
|
function addDRButton() {
|
||||||
try {
|
try {
|
||||||
// Avoid duplicates
|
// Avoid duplicates
|
||||||
if (html.querySelector(".dr-quick-button")) return;
|
//if (document.querySelector(".dr-quick-button")) return;
|
||||||
|
|
||||||
const container =
|
|
||||||
html.querySelector(".dice-tray") ||
|
|
||||||
html.querySelector(".chat-controls .control-buttons") ||
|
|
||||||
html.querySelector(".chat-controls") ||
|
|
||||||
html;
|
|
||||||
|
|
||||||
// Build button
|
// Build button
|
||||||
const btn = document.createElement("button");
|
const btn = document.createElement("button");
|
||||||
btn.type = "button";
|
btn.type = "button";
|
||||||
btn.className = "dr-quick-button";
|
btn.className = "ui-control icon fas-solid dr-quick-button";
|
||||||
btn.title = "Duality Dice Roll";
|
btn.title = "Duality Dice Roll";
|
||||||
btn.setAttribute("aria-label", "Duality Dice Roll");
|
btn.setAttribute("aria-label", "Duality Dice Roll");
|
||||||
|
|
||||||
|
|
@ -56,18 +50,14 @@ function addDRButton(html) {
|
||||||
</g>
|
</g>
|
||||||
</svg>
|
</svg>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
btn.addEventListener("click", async () => {
|
btn.addEventListener("click", async () => {
|
||||||
|
console.log("clicked the button");
|
||||||
await runDRCommand();
|
await runDRCommand();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Append the button at the end of the roll-privacy div
|
// Find all roll-privacy divs and append the button
|
||||||
const rollPrivacyDiv = container.querySelector("#roll-privacy");
|
const rollPrivacyDivs = document.querySelectorAll("#roll-privacy");
|
||||||
if (rollPrivacyDiv) {
|
rollPrivacyDivs.forEach(div => div.appendChild(btn.cloneNode(true)));
|
||||||
rollPrivacyDiv.appendChild(btn);
|
|
||||||
} else {
|
|
||||||
container.appendChild(btn); // fallback if the div doesn't exist
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("DR Quick Button | addDRButton error:", err);
|
console.error("DR Quick Button | addDRButton error:", err);
|
||||||
|
|
@ -75,37 +65,14 @@ function addDRButton(html) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** Run `/dr` as if typed into chat */
|
/** Run `/dr` as if typed into chat */
|
||||||
async function runDRCommand() {
|
async function runDRCommand() {
|
||||||
const cmd = "/dr";
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (ui?.chat?.processMessage) return await ui.chat.processMessage(cmd);
|
await ChatMessage.create({ content: "/dr" });
|
||||||
} catch (e) {
|
} catch (err) {
|
||||||
console.warn("DR Quick Button | ui.chat.processMessage failed:", e);
|
console.error("DR Quick Button | Failed to send /dr command:", err);
|
||||||
|
ui.notifications?.warn("Couldn't run /dr automatically. Try typing /dr in chat.");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
if (globalThis.ChatLog?.instance?.processMessage) {
|
|
||||||
return await globalThis.ChatLog.instance.processMessage(cmd);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.warn("DR Quick Button | ChatLog.instance.processMessage failed:", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const form = ui.chat?.element?.querySelector?.("form#chat-form");
|
|
||||||
const textarea = form?.querySelector?.("textarea[name='message']");
|
|
||||||
if (form && textarea) {
|
|
||||||
const prev = textarea.value;
|
|
||||||
textarea.value = cmd;
|
|
||||||
form.dispatchEvent(new Event("submit", { bubbles: true, cancelable: true }));
|
|
||||||
setTimeout(() => (textarea.value = prev ?? ""), 0);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.warn("DR Quick Button | Fallback submit failed:", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
ui.notifications?.warn?.("Couldn't run /dr automatically. Try typing /dr in chat.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue