Spaces:
Running
Running
Update index.html
Browse files- index.html +7 -15
index.html
CHANGED
|
@@ -203,7 +203,7 @@
|
|
| 203 |
<div class="magic-card p-1 rounded-2xl w-full relative magic-border mt-4 hover:scale-[1.02] transition-transform duration-500">
|
| 204 |
<div class="bg-slate-900 rounded-xl overflow-hidden relative z-10">
|
| 205 |
<!-- Changed classes to support landscape banner -->
|
| 206 |
-
<!--
|
| 207 |
<img id="result-image" src="" alt="Role Image" class="w-full h-auto object-contain shadow-lg">
|
| 208 |
</div>
|
| 209 |
</div>
|
|
@@ -320,6 +320,8 @@
|
|
| 320 |
}
|
| 321 |
],
|
| 322 |
|
|
|
|
|
|
|
| 323 |
resultsData: {
|
| 324 |
world: {
|
| 325 |
title: "世界架構師",
|
|
@@ -521,15 +523,6 @@
|
|
| 521 |
}, 500);
|
| 522 |
},
|
| 523 |
|
| 524 |
-
restartQuiz: function() {
|
| 525 |
-
this.resultScreen.classList.add('fade-out');
|
| 526 |
-
setTimeout(() => {
|
| 527 |
-
this.resultScreen.classList.add('hidden');
|
| 528 |
-
this.resultScreen.classList.remove('fade-out');
|
| 529 |
-
this.startQuiz();
|
| 530 |
-
}, 500);
|
| 531 |
-
},
|
| 532 |
-
|
| 533 |
shareResult: async function() {
|
| 534 |
const shareBtn = document.getElementById('share-btn');
|
| 535 |
const originalContent = shareBtn.innerHTML;
|
|
@@ -547,18 +540,17 @@
|
|
| 547 |
captureElement.style.backgroundColor = '#0f172a'; // Dark blue bg
|
| 548 |
captureElement.style.padding = '20px'; // Add padding for screenshot
|
| 549 |
|
| 550 |
-
//
|
| 551 |
-
// 確保圖片載入完成,否則截圖可能是空白
|
| 552 |
const resultImage = document.getElementById('result-image');
|
| 553 |
if (!resultImage.complete) {
|
| 554 |
await new Promise((resolve) => { resultImage.onload = resolve; });
|
| 555 |
}
|
| 556 |
|
|
|
|
| 557 |
const canvas = await html2canvas(captureElement, {
|
| 558 |
backgroundColor: '#0f172a',
|
| 559 |
scale: 2, // High resolution
|
| 560 |
-
useCORS: true, //
|
| 561 |
-
allowTaint: true, // 允許繪製(即使可能 tainted)
|
| 562 |
logging: false
|
| 563 |
});
|
| 564 |
|
|
@@ -604,7 +596,7 @@
|
|
| 604 |
|
| 605 |
} catch (error) {
|
| 606 |
console.error('Error generating image:', error);
|
| 607 |
-
alert('
|
| 608 |
shareBtn.innerHTML = originalContent;
|
| 609 |
shareBtn.disabled = false;
|
| 610 |
}
|
|
|
|
| 203 |
<div class="magic-card p-1 rounded-2xl w-full relative magic-border mt-4 hover:scale-[1.02] transition-transform duration-500">
|
| 204 |
<div class="bg-slate-900 rounded-xl overflow-hidden relative z-10">
|
| 205 |
<!-- Changed classes to support landscape banner -->
|
| 206 |
+
<!-- 圖片來源將會是相對路徑,無需 crossorigin,且因為同源,截圖沒問題 -->
|
| 207 |
<img id="result-image" src="" alt="Role Image" class="w-full h-auto object-contain shadow-lg">
|
| 208 |
</div>
|
| 209 |
</div>
|
|
|
|
| 320 |
}
|
| 321 |
],
|
| 322 |
|
| 323 |
+
// 圖片已改為本地路徑 (Local Paths)
|
| 324 |
+
// 請確保 1.png, 2.png, 3.png, 4.png 與 index.html 位於同一目錄下
|
| 325 |
resultsData: {
|
| 326 |
world: {
|
| 327 |
title: "世界架構師",
|
|
|
|
| 523 |
}, 500);
|
| 524 |
},
|
| 525 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 526 |
shareResult: async function() {
|
| 527 |
const shareBtn = document.getElementById('share-btn');
|
| 528 |
const originalContent = shareBtn.innerHTML;
|
|
|
|
| 540 |
captureElement.style.backgroundColor = '#0f172a'; // Dark blue bg
|
| 541 |
captureElement.style.padding = '20px'; // Add padding for screenshot
|
| 542 |
|
| 543 |
+
// 關鍵修正:等待圖片載入完成,確保截圖不空白
|
|
|
|
| 544 |
const resultImage = document.getElementById('result-image');
|
| 545 |
if (!resultImage.complete) {
|
| 546 |
await new Promise((resolve) => { resultImage.onload = resolve; });
|
| 547 |
}
|
| 548 |
|
| 549 |
+
// 簡化後的 html2canvas,移除 proxy 邏輯
|
| 550 |
const canvas = await html2canvas(captureElement, {
|
| 551 |
backgroundColor: '#0f172a',
|
| 552 |
scale: 2, // High resolution
|
| 553 |
+
useCORS: true, // 同源圖片使用這個屬性依然安全且標準
|
|
|
|
| 554 |
logging: false
|
| 555 |
});
|
| 556 |
|
|
|
|
| 596 |
|
| 597 |
} catch (error) {
|
| 598 |
console.error('Error generating image:', error);
|
| 599 |
+
alert('圖片生成失敗,請稍後再試或使用手機原生截圖。');
|
| 600 |
shareBtn.innerHTML = originalContent;
|
| 601 |
shareBtn.disabled = false;
|
| 602 |
}
|