diff --git a/static/index.html b/static/index.html index 72e0ec7..66bb3e5 100644 --- a/static/index.html +++ b/static/index.html @@ -174,6 +174,7 @@ textarea { resize: vertical; } +
Select a deck or submit a new one.
@@ -286,6 +287,7 @@ function updateHeader(d) { const terminal = complete || d.status === "failed"; const isMox = d.source === "moxfield"; document.getElementById("dlBtn").style.display = complete && !editMode ? "" : "none"; + document.getElementById("copyListBtn").style.display = !editMode ? "" : "none"; document.getElementById("delBtn").style.display = terminal && !editMode ? "" : "none"; document.getElementById("editBtn").style.display = terminal && !editMode && !isMox ? "" : "none"; document.getElementById("syncBtn").style.display = terminal && !editMode && isMox ? "" : "none"; @@ -689,6 +691,39 @@ async function copyTTSUrl() { } } +function buildMoxfieldText() { + const deck = deckData[activeDeck]; + if (!deck) return ""; + const counts = new Map(); + currentCards.forEach(c => { + if (c.is_token) return; + counts.set(c.name, (counts.get(c.name) || 0) + 1); + }); + const commanders = (deck.commander || "").split("\n").map(s => s.trim()).filter(Boolean); + const lines = commanders.map(name => { + const left = (counts.get(name) || 1) - 1; + if (left > 0) counts.set(name, left); else counts.delete(name); + return `1 ${name}`; + }); + if (commanders.length) lines.push(""); + for (const [name, qty] of counts) lines.push(`${qty} ${name}`); + return lines.join("\n"); +} + +async function copyMoxfieldList() { + if (!activeDeck) return; + const text = buildMoxfieldText(); + const btn = document.getElementById("copyListBtn"); + try { + await navigator.clipboard.writeText(text); + const orig = btn.textContent; + btn.textContent = "Copied!"; + setTimeout(() => btn.textContent = orig, 1500); + } catch { + prompt("Copy this list:", text); + } +} + function esc(s) { return String(s).replace(/&/g,"&").replace(//g,">").replace(/"/g,"""); }