Copy Deck

This commit is contained in:
2026-07-23 20:28:38 -05:00
parent b2a0b59cbe
commit 8b2e99a588
+35
View File
@@ -174,6 +174,7 @@ textarea { resize: vertical; }
<button class="btn" id="cancelBtn" onclick="exitEditMode(true)" style="display:none">Cancel</button>
<button class="btn" id="sortBtn" onclick="toggleSort()" style="display:none">Sort: Default</button>
<button class="btn btn-blue" id="dlBtn" onclick="copyTTSUrl()" style="display:none">Copy URL</button>
<button class="btn btn-blue" id="copyListBtn" onclick="copyMoxfieldList()" style="display:none">Copy List</button>
<button class="btn btn-red" id="delBtn" onclick="deleteDeck()" style="display:none">Delete</button>
</div>
<div class="card-area" id="cardArea"><div class="placeholder">Select a deck or submit a new one.</div></div>
@@ -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,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;");
}