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:
+12
-9
@@ -208,19 +208,19 @@ Hooks.on("getSceneControlButtons", (controls) => {
|
||||
}
|
||||
})
|
||||
|
||||
// Add system buttons to the chat log
|
||||
Hooks.on("renderChatLog", (chatLog, html) => {
|
||||
const form = html[0]?.querySelector("#chat-form")
|
||||
if (!form || form.querySelector(".hamalron-chat-tools")) return
|
||||
// Add system buttons to the chat sidebar
|
||||
function addChatTools() {
|
||||
const controls = document.querySelector("#chat-controls")
|
||||
if (!controls || controls.querySelector(".hamalron-chat-tools")) return
|
||||
|
||||
const tools = document.createElement("div")
|
||||
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 btn = document.createElement("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.title = title
|
||||
btn.addEventListener("click", onClick)
|
||||
@@ -229,7 +229,7 @@ Hooks.on("renderChatLog", (chatLog, html) => {
|
||||
tools.appendChild(btn)
|
||||
}
|
||||
|
||||
if (game.user.isGM) {
|
||||
if (game.user?.isGM) {
|
||||
addBtn("fas fa-cards", "Tarot", game.i18n.localize("HAMALRON.TarotDeck.Title"), () => {
|
||||
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
|
||||
globalThis._initiativeCardMap = new Map()
|
||||
|
||||
Reference in New Issue
Block a user