From 2c73c49b0b16e7b2b285a47dbaf67aee7ce025de Mon Sep 17 00:00:00 2001 From: cptn-cosmo Date: Mon, 1 Sep 2025 00:00:51 +0200 Subject: [PATCH 1/3] initial work to get the button wokring again --- module.json | 4 +-- scripts/dr-button.js | 59 ++++++++++---------------------------------- 2 files changed, 15 insertions(+), 48 deletions(-) diff --git a/module.json b/module.json index 5900e46..f0402af 100644 --- a/module.json +++ b/module.json @@ -2,7 +2,7 @@ "id": "duality-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.", - "version": "0.1.3", + "version": "0.1.4", "compatibility": { "minimum": "13", "verified": "13" @@ -16,5 +16,5 @@ "languages": [], "url": "https://github.com/cptn-cosmo/DualityDiceRoller", "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" } diff --git a/scripts/dr-button.js b/scripts/dr-button.js index 60ab202..e9c8f07 100644 --- a/scripts/dr-button.js +++ b/scripts/dr-button.js @@ -13,21 +13,15 @@ Hooks.on("renderChatLog", (app, html) => addDRButton(html)); // Mini/Popout chat Hooks.on("renderChatPopout", (app, html) => addDRButton(html)); -function addDRButton(html) { +function addDRButton() { try { // Avoid duplicates - if (html.querySelector(".dr-quick-button")) return; - - const container = - html.querySelector(".dice-tray") || - html.querySelector(".chat-controls .control-buttons") || - html.querySelector(".chat-controls") || - html; + //if (document.querySelector(".dr-quick-button")) return; // Build button const btn = document.createElement("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.setAttribute("aria-label", "Duality Dice Roll"); @@ -56,18 +50,14 @@ function addDRButton(html) { `; - btn.addEventListener("click", async () => { + console.log("clicked the button"); await runDRCommand(); }); - // Append the button at the end of the roll-privacy div - const rollPrivacyDiv = container.querySelector("#roll-privacy"); - if (rollPrivacyDiv) { - rollPrivacyDiv.appendChild(btn); - } else { - container.appendChild(btn); // fallback if the div doesn't exist - } + // Find all roll-privacy divs and append the button + const rollPrivacyDivs = document.querySelectorAll("#roll-privacy"); + rollPrivacyDivs.forEach(div => div.appendChild(btn.cloneNode(true))); } catch (err) { console.error("DR Quick Button | addDRButton error:", err); @@ -75,37 +65,14 @@ function addDRButton(html) { } + /** Run `/dr` as if typed into chat */ async function runDRCommand() { - const cmd = "/dr"; - try { - if (ui?.chat?.processMessage) return await ui.chat.processMessage(cmd); - } catch (e) { - console.warn("DR Quick Button | ui.chat.processMessage failed:", e); + await ChatMessage.create({ content: "/dr" }); + } catch (err) { + 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."); } + From e7138d25fcbe5e38a6c8bfe9cda2a9157d3648d1 Mon Sep 17 00:00:00 2001 From: Mysteryusy Date: Mon, 1 Sep 2025 00:53:53 +0200 Subject: [PATCH 2/3] Fix everything --- scripts/dr-button.js | 15 ++++++++------- styles/dr-button.css | 21 ++++++--------------- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/scripts/dr-button.js b/scripts/dr-button.js index e9c8f07..26e6eb3 100644 --- a/scripts/dr-button.js +++ b/scripts/dr-button.js @@ -8,15 +8,15 @@ Hooks.once("init", () => { }); // Sidebar chat -Hooks.on("renderChatLog", (app, html) => addDRButton(html)); +Hooks.on("renderChatLog", (_app, _html) => addDRButton()); // Mini/Popout chat -Hooks.on("renderChatPopout", (app, html) => addDRButton(html)); +Hooks.on("renderChatPopout", (_app, _html) => addDRButton()); function addDRButton() { try { - // Avoid duplicates - //if (document.querySelector(".dr-quick-button")) return; + const container = document.createElement("div"); + container.className = "dr-quick-button-container"; // Build button const btn = document.createElement("button"); @@ -51,13 +51,14 @@ function addDRButton() { `; btn.addEventListener("click", async () => { - console.log("clicked the button"); await runDRCommand(); }); + container.appendChild(btn); + // Find all roll-privacy divs and append the button const rollPrivacyDivs = document.querySelectorAll("#roll-privacy"); - rollPrivacyDivs.forEach(div => div.appendChild(btn.cloneNode(true))); + rollPrivacyDivs.forEach(div => div.appendChild(container)); } catch (err) { console.error("DR Quick Button | addDRButton error:", err); @@ -69,7 +70,7 @@ function addDRButton() { /** Run `/dr` as if typed into chat */ async function runDRCommand() { try { - await ChatMessage.create({ content: "/dr" }); + await ui?.chat?.processMessage("/dr"); } catch (err) { console.error("DR Quick Button | Failed to send /dr command:", err); ui.notifications?.warn("Couldn't run /dr automatically. Try typing /dr in chat."); diff --git a/styles/dr-button.css b/styles/dr-button.css index dabe6d5..885c42d 100644 --- a/styles/dr-button.css +++ b/styles/dr-button.css @@ -3,22 +3,13 @@ display: inline-flex; align-items: center; justify-content: center; - width: 28px; - height: 28px; - margin-left: 4px; - border: 1px solid var(--color-border-light-2, #8882); - border-radius: 4px; - background: var(--color-bg, #222e); - cursor: pointer; - padding: 1; + padding: 7px; } -.dr-quick-button:hover { - filter: brightness(1.15); +.dr-quick-button-container { + margin: 0px 10px; } -.dr-quick-button img { - width: 18px; - height: 18px; - pointer-events: none; -} +.vertical .dr-quick-button-container { + margin: 10px 0px; +} \ No newline at end of file From 68e518bee23b17acf34bbf22898871b8ce58f913 Mon Sep 17 00:00:00 2001 From: cptn-cosmo Date: Mon, 1 Sep 2025 00:58:22 +0200 Subject: [PATCH 3/3] fixed button and new look --- scripts/dr-button.js | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/scripts/dr-button.js b/scripts/dr-button.js index 26e6eb3..ccd5c22 100644 --- a/scripts/dr-button.js +++ b/scripts/dr-button.js @@ -26,29 +26,7 @@ function addDRButton() { btn.setAttribute("aria-label", "Duality Dice Roll"); // Inline SVG (or use icon.src = "modules/dr-quick-button/icons/dr.svg"; if external) - btn.innerHTML = ` - - - - - - - - - - - - - - - - - - + btn.innerHTML = `DR `; btn.addEventListener("click", async () => { await runDRCommand();