LazyHuman10 commited on
Commit ·
73c0075
1
Parent(s): 2b6b8bb
added image in NPC card
Browse files- index.html +26 -5
index.html
CHANGED
|
@@ -860,18 +860,39 @@
|
|
| 860 |
async function exportShareCard() {
|
| 861 |
if (!currentNPC) return;
|
| 862 |
shareBtn.disabled = true;
|
|
|
|
| 863 |
try {
|
| 864 |
-
|
| 865 |
-
|
| 866 |
-
|
| 867 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 868 |
shareImage.style.display = "block";
|
| 869 |
-
downloadLink.href =
|
| 870 |
downloadLink.style.display = "inline-block";
|
| 871 |
} catch (err) {
|
|
|
|
| 872 |
showError();
|
| 873 |
} finally {
|
| 874 |
shareBtn.disabled = false;
|
|
|
|
| 875 |
}
|
| 876 |
}
|
| 877 |
|
|
|
|
| 860 |
async function exportShareCard() {
|
| 861 |
if (!currentNPC) return;
|
| 862 |
shareBtn.disabled = true;
|
| 863 |
+
shareBtn.textContent = "📤 Exporting…";
|
| 864 |
try {
|
| 865 |
+
// Dynamically load html2canvas if not already loaded
|
| 866 |
+
if (typeof html2canvas === "undefined") {
|
| 867 |
+
await new Promise((resolve, reject) => {
|
| 868 |
+
const s = document.createElement("script");
|
| 869 |
+
s.src = "https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js";
|
| 870 |
+
s.onload = resolve;
|
| 871 |
+
s.onerror = () => reject(new Error("Failed to load html2canvas"));
|
| 872 |
+
document.head.appendChild(s);
|
| 873 |
+
});
|
| 874 |
+
}
|
| 875 |
+
|
| 876 |
+
// Capture the actual rendered card element
|
| 877 |
+
const canvas = await html2canvas(characterCard, {
|
| 878 |
+
backgroundColor: "#0d0d1a",
|
| 879 |
+
scale: 2, // high-res export
|
| 880 |
+
useCORS: true,
|
| 881 |
+
allowTaint: true,
|
| 882 |
+
logging: false,
|
| 883 |
+
});
|
| 884 |
+
|
| 885 |
+
const dataUrl = canvas.toDataURL("image/png");
|
| 886 |
+
shareImage.src = dataUrl;
|
| 887 |
shareImage.style.display = "block";
|
| 888 |
+
downloadLink.href = dataUrl;
|
| 889 |
downloadLink.style.display = "inline-block";
|
| 890 |
} catch (err) {
|
| 891 |
+
console.error("Export failed:", err);
|
| 892 |
showError();
|
| 893 |
} finally {
|
| 894 |
shareBtn.disabled = false;
|
| 895 |
+
shareBtn.textContent = "📤 Export Share Card";
|
| 896 |
}
|
| 897 |
}
|
| 898 |
|