fix: boutons Tarot/Actions/Sort visibles dans le tchat

Utilise setTimeout pour laisser le DOM se stabiliser avant d'injecter
les boutons au-dessus de #chat-controls.
This commit is contained in:
2026-07-10 23:31:42 +02:00
parent d5772864b7
commit 0b0124e0c9
+12 -9
View File
@@ -208,19 +208,19 @@ Hooks.on("getSceneControlButtons", (controls) => {
} }
}) })
// Add system buttons to the chat log // Add system buttons to the chat sidebar
Hooks.on("renderChatLog", (chatLog, html) => { function addChatTools() {
const form = html[0]?.querySelector("#chat-form") const controls = document.querySelector("#chat-controls")
if (!form || form.querySelector(".hamalron-chat-tools")) return if (!controls || controls.querySelector(".hamalron-chat-tools")) return
const tools = document.createElement("div") const tools = document.createElement("div")
tools.className = "hamalron-chat-tools" tools.className = "hamalron-chat-tools"
tools.style.cssText = "display:flex;gap:4px;padding:4px 0;border-bottom:1px solid #333;margin-bottom:4px" tools.style.cssText = "display:flex;gap:4px;padding:4px 8px;border-bottom:1px solid #444;margin-bottom:2px;flex-wrap:wrap"
const addBtn = (icon, label, title, onClick) => { const addBtn = (icon, label, title, onClick) => {
const btn = document.createElement("button") const btn = document.createElement("button")
btn.type = "button" btn.type = "button"
btn.style.cssText = "display:flex;align-items:center;gap:4px;padding:3px 8px;background:#2a2a4a;color:#e0e0e0;border:1px solid #555;border-radius:4px;cursor:pointer;font-size:11px" btn.style.cssText = "display:flex;align-items:center;gap:4px;padding:3px 8px;background:#2a2a4a;color:#e0e0e0;border:1px solid #555;border-radius:4px;cursor:pointer;font-size:11px;white-space:nowrap"
btn.innerHTML = `<i class="${icon}"></i> <span>${label}</span>` btn.innerHTML = `<i class="${icon}"></i> <span>${label}</span>`
btn.title = title btn.title = title
btn.addEventListener("click", onClick) btn.addEventListener("click", onClick)
@@ -229,7 +229,7 @@ Hooks.on("renderChatLog", (chatLog, html) => {
tools.appendChild(btn) tools.appendChild(btn)
} }
if (game.user.isGM) { if (game.user?.isGM) {
addBtn("fas fa-cards", "Tarot", game.i18n.localize("HAMALRON.TarotDeck.Title"), () => { addBtn("fas fa-cards", "Tarot", game.i18n.localize("HAMALRON.TarotDeck.Title"), () => {
game.system.api.openTarotDeckManager() game.system.api.openTarotDeckManager()
}) })
@@ -247,8 +247,11 @@ Hooks.on("renderChatLog", (chatLog, html) => {
} }
}) })
form.parentNode.insertBefore(tools, form) controls.parentNode.insertBefore(tools, controls)
}) }
Hooks.on("renderChatLog", () => setTimeout(addChatTools, 0))
Hooks.on("collapseSidebar", () => setTimeout(addChatTools, 100))
// Store card info from initiative rolls for the chat hook // Store card info from initiative rolls for the chat hook
globalThis._initiativeCardMap = new Map() globalThis._initiativeCardMap = new Map()