Compare commits
No commits in common. "f826e27523670b7fca988f4d953f3a22d8d985f4" and "076fcfc1c471eeaf757c5401393c1a7c30ea19ae" have entirely different histories.
f826e27523
...
076fcfc1c4
2 changed files with 3 additions and 64 deletions
13
web/static/js/jszip.min.js
vendored
13
web/static/js/jszip.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -64,7 +64,6 @@
|
|||
|
||||
</div>
|
||||
|
||||
<script src="{{ url_for('static', filename='js/jszip.min.js') }}"></script>
|
||||
<script>
|
||||
const canvas = document.getElementById("cardCanvas");
|
||||
const ctx = canvas.getContext("2d");
|
||||
|
@ -222,17 +221,13 @@ function wrapText(text, x, y, maxWidth, lineHeight) {
|
|||
|
||||
// Download button
|
||||
downloadBtn.addEventListener("click", () => {
|
||||
// Sanitize file name
|
||||
const safeName = (nameInput.value || "card").replace(/[^a-z0-9_\-]/gi, "_");
|
||||
const safePack = (packInput.value || "pack").replace(/[^a-z0-9_\-]/gi, "_");
|
||||
const fileName = `kemoverse_${safePack}_${safeName}.webp`;
|
||||
|
||||
const link = document.createElement("a");
|
||||
link.download = fileName;
|
||||
link.download = "kemoverse-card.webp";
|
||||
link.href = canvas.toDataURL("image/webp", 0.95);
|
||||
link.click();
|
||||
});
|
||||
|
||||
// Create and place the JSON download button below the card download button
|
||||
const jsonBtn = document.createElement("button");
|
||||
jsonBtn.textContent = "Download Card Info";
|
||||
jsonBtn.style.marginTop = "0.5rem";
|
||||
|
@ -247,56 +242,13 @@ jsonBtn.onclick = () => {
|
|||
artist: artistInput.value,
|
||||
frame: frameSelect.value
|
||||
};
|
||||
const safeName = (nameInput.value || "card").replace(/[^a-z0-9_\-]/gi, "_");
|
||||
const safePack = (packInput.value || "pack").replace(/[^a-z0-9_\-]/gi, "_");
|
||||
const fileName = `kemoverse_${safePack}_${safeName}.json`;
|
||||
|
||||
const blob = new Blob([JSON.stringify(cardData, null, 2)], {type: "application/json"});
|
||||
const link = document.createElement("a");
|
||||
link.href = URL.createObjectURL(blob);
|
||||
link.download = fileName;
|
||||
link.download = "kemoverse-card.json";
|
||||
link.click();
|
||||
};
|
||||
|
||||
// Place the button below the downloadBtn
|
||||
downloadBtn.parentNode.insertBefore(jsonBtn, downloadBtn.nextSibling);
|
||||
|
||||
const zipBtn = document.createElement("button");
|
||||
zipBtn.textContent = "Download Card ZIP";
|
||||
zipBtn.style.marginTop = "0.5rem";
|
||||
zipBtn.onclick = async () => {
|
||||
const cardData = {
|
||||
name: nameInput.value,
|
||||
pack: packInput.value,
|
||||
power: powerInput.value,
|
||||
charm: charmInput.value,
|
||||
wit: witInput.value,
|
||||
flavor: flavorInput.value,
|
||||
artist: artistInput.value,
|
||||
frame: frameSelect.value
|
||||
};
|
||||
const safeName = (nameInput.value || "card").replace(/[^a-z0-9_\-]/gi, "_");
|
||||
const safePack = (packInput.value || "pack").replace(/[^a-z0-9_\-]/gi, "_");
|
||||
const imgFileName = `kemoverse_${safePack}_${safeName}.webp`;
|
||||
const jsonFileName = `kemoverse_${safePack}_${safeName}.json`;
|
||||
|
||||
// Create ZIP
|
||||
const zip = new JSZip();
|
||||
// Add image
|
||||
const imgData = canvas.toDataURL("image/webp", 0.95).split(',')[1];
|
||||
zip.file(imgFileName, imgData, {base64: true});
|
||||
// Add JSON
|
||||
zip.file(jsonFileName, JSON.stringify(cardData, null, 2));
|
||||
|
||||
// Generate and download
|
||||
const content = await zip.generateAsync({type: "blob"});
|
||||
const link = document.createElement("a");
|
||||
link.href = URL.createObjectURL(content);
|
||||
link.download = `kemoverse_${safePack}_${safeName}.zip`;
|
||||
link.click();
|
||||
};
|
||||
|
||||
// Place the button below the downloadBtn
|
||||
downloadBtn.parentNode.insertBefore(zipBtn, downloadBtn.nextSibling);
|
||||
</script>
|
||||
{% endblock %}
|
Loading…
Add table
Reference in a new issue