Spaces:
Running
Running
Update index.html
Browse files- index.html +117 -62
index.html
CHANGED
|
@@ -10,6 +10,8 @@
|
|
| 10 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
| 11 |
<!-- Google Fonts -->
|
| 12 |
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@300;500;700&family=Orbitron:wght@500;700&display=swap" rel="stylesheet">
|
|
|
|
|
|
|
| 13 |
|
| 14 |
<script>
|
| 15 |
tailwind.config = {
|
|
@@ -195,51 +197,56 @@
|
|
| 195 |
<!-- RESULT SCREEN -->
|
| 196 |
<div id="result-screen" class="hidden text-center space-y-6">
|
| 197 |
|
| 198 |
-
<!--
|
| 199 |
-
<div
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
</div>
|
| 204 |
-
</div>
|
| 205 |
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
|
|
|
| 221 |
</div>
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
</
|
| 233 |
</div>
|
| 234 |
</div>
|
| 235 |
</div>
|
|
|
|
| 236 |
|
| 237 |
<div class="pt-4 fade-in flex flex-col md:flex-row justify-center gap-4" style="animation-delay: 0.6s;">
|
| 238 |
<button onclick="quizApp.restartQuiz()" class="px-8 py-3 bg-slate-800 hover:bg-slate-700 border border-slate-600 rounded-full text-slate-300 transition-all hover:text-white hover:border-cyan-400 flex items-center justify-center gap-2 order-2 md:order-1">
|
| 239 |
<i class="fa-solid fa-rotate-right"></i> 重新測驗
|
| 240 |
</button>
|
| 241 |
-
<button onclick="quizApp.shareResult()" class="px-8 py-3 bg-gradient-to-r from-cyan-500 to-purple-500 hover:from-cyan-600 hover:to-purple-600 border border-transparent rounded-full text-white transition-all flex items-center justify-center gap-2 order-1 md:order-2 magic-border">
|
| 242 |
-
<i class="fa-solid fa-share-nodes"></i>
|
| 243 |
</button>
|
| 244 |
</div>
|
| 245 |
</div>
|
|
@@ -286,7 +293,7 @@
|
|
| 286 |
text: "將遊戲引入教學,最大的風險是?",
|
| 287 |
options: [
|
| 288 |
{ text: "設計得不好玩,學生覺得尷尬。", scores: { alch: 1, adv: 1 } },
|
| 289 |
-
{ text: "只有好玩,但沒學到東西。", scores: { world: 1,adv: 1, alch: 1 } },
|
| 290 |
{ text: "準備時間太長,無法保證成效。", scores: { world: 1, alch: 1 } },
|
| 291 |
{ text: "秩序失控,學生只想玩不想上課。", scores: { truth: 2 } }
|
| 292 |
]
|
|
@@ -523,36 +530,84 @@
|
|
| 523 |
}, 500);
|
| 524 |
},
|
| 525 |
|
| 526 |
-
shareResult: function() {
|
| 527 |
-
const
|
| 528 |
-
const
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 541 |
});
|
| 542 |
-
} else {
|
| 543 |
-
// Fallback for desktops or unsupported browsers
|
| 544 |
-
this.copyToClipboard(shareText + shareUrl);
|
| 545 |
-
}
|
| 546 |
-
},
|
| 547 |
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 556 |
}
|
| 557 |
};
|
| 558 |
|
|
|
|
| 10 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
| 11 |
<!-- Google Fonts -->
|
| 12 |
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@300;500;700&family=Orbitron:wght@500;700&display=swap" rel="stylesheet">
|
| 13 |
+
<!-- html2canvas (截圖功能核心) -->
|
| 14 |
+
<script src="https://html2canvas.hertzen.com/dist/html2canvas.min.js"></script>
|
| 15 |
|
| 16 |
<script>
|
| 17 |
tailwind.config = {
|
|
|
|
| 197 |
<!-- RESULT SCREEN -->
|
| 198 |
<div id="result-screen" class="hidden text-center space-y-6">
|
| 199 |
|
| 200 |
+
<!-- Result Content Wrapper for Capture (ID added here) -->
|
| 201 |
+
<div id="result-capture-area" class="bg-slate-900/0 rounded-2xl p-2 md:p-4 transition-colors">
|
| 202 |
+
<!-- Modified Image Container for Banner (1375x763) -->
|
| 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="anonymous" 以確保畫面正常顯示,但這可能會影響截圖 -->
|
| 207 |
+
<img id="result-image" src="" alt="Role Image" class="w-full h-auto object-contain shadow-lg">
|
| 208 |
+
</div>
|
| 209 |
</div>
|
|
|
|
| 210 |
|
| 211 |
+
<div class="space-y-2 fade-in mt-6" style="animation-delay: 0.2s;">
|
| 212 |
+
<p class="text-cyan-400 font-tech tracking-widest text-sm uppercase">Class Awakened</p>
|
| 213 |
+
<h2 id="result-title" class="text-3xl md:text-4xl font-bold text-transparent bg-clip-text bg-gradient-to-r from-purple-400 to-cyan-400">
|
| 214 |
+
職業名稱
|
| 215 |
+
</h2>
|
| 216 |
+
</div>
|
| 217 |
|
| 218 |
+
<div class="magic-card p-6 rounded-xl text-left space-y-4 fade-in mt-6" style="animation-delay: 0.4s;">
|
| 219 |
+
<div class="flex items-start gap-3">
|
| 220 |
+
<i class="fa-solid fa-scroll text-purple-400 mt-1"></i>
|
| 221 |
+
<div>
|
| 222 |
+
<h3 class="text-purple-300 font-bold mb-1">天賦解析</h3>
|
| 223 |
+
<p id="result-desc" class="text-slate-300 text-sm leading-relaxed">
|
| 224 |
+
描述文字...
|
| 225 |
+
</p>
|
| 226 |
+
</div>
|
| 227 |
</div>
|
| 228 |
+
|
| 229 |
+
<div class="border-t border-slate-700 my-2"></div>
|
| 230 |
+
|
| 231 |
+
<div class="flex items-start gap-3">
|
| 232 |
+
<i class="fa-solid fa-dungeon text-cyan-400 mt-1"></i>
|
| 233 |
+
<div>
|
| 234 |
+
<h3 class="text-cyan-300 font-bold mb-1">本場研習使命</h3>
|
| 235 |
+
<p id="result-mission" class="text-slate-200 font-medium text-sm leading-relaxed bg-slate-800/50 p-3 rounded-lg border-l-2 border-cyan-500">
|
| 236 |
+
使命文字...
|
| 237 |
+
</p>
|
| 238 |
+
</div>
|
| 239 |
</div>
|
| 240 |
</div>
|
| 241 |
</div>
|
| 242 |
+
<!-- End Capture Area -->
|
| 243 |
|
| 244 |
<div class="pt-4 fade-in flex flex-col md:flex-row justify-center gap-4" style="animation-delay: 0.6s;">
|
| 245 |
<button onclick="quizApp.restartQuiz()" class="px-8 py-3 bg-slate-800 hover:bg-slate-700 border border-slate-600 rounded-full text-slate-300 transition-all hover:text-white hover:border-cyan-400 flex items-center justify-center gap-2 order-2 md:order-1">
|
| 246 |
<i class="fa-solid fa-rotate-right"></i> 重新測驗
|
| 247 |
</button>
|
| 248 |
+
<button id="share-btn" onclick="quizApp.shareResult()" class="px-8 py-3 bg-gradient-to-r from-cyan-500 to-purple-500 hover:from-cyan-600 hover:to-purple-600 border border-transparent rounded-full text-white transition-all flex items-center justify-center gap-2 order-1 md:order-2 magic-border shadow-lg shadow-cyan-500/30">
|
| 249 |
+
<i class="fa-solid fa-share-nodes"></i> 分享結果圖片
|
| 250 |
</button>
|
| 251 |
</div>
|
| 252 |
</div>
|
|
|
|
| 293 |
text: "將遊戲引入教學,最大的風險是?",
|
| 294 |
options: [
|
| 295 |
{ text: "設計得不好玩,學生覺得尷尬。", scores: { alch: 1, adv: 1 } },
|
| 296 |
+
{ text: "只有好玩,但沒學到東西。", scores: { world: 1, adv: 1, alch: 1 } },
|
| 297 |
{ text: "準備時間太長,無法保證成效。", scores: { world: 1, alch: 1 } },
|
| 298 |
{ text: "秩序失控,學生只想玩不想上課。", scores: { truth: 2 } }
|
| 299 |
]
|
|
|
|
| 530 |
}, 500);
|
| 531 |
},
|
| 532 |
|
| 533 |
+
shareResult: async function() {
|
| 534 |
+
const shareBtn = document.getElementById('share-btn');
|
| 535 |
+
const originalContent = shareBtn.innerHTML;
|
| 536 |
+
|
| 537 |
+
// Loading State
|
| 538 |
+
shareBtn.innerHTML = '<i class="fa-solid fa-spinner fa-spin"></i> 圖片生成中...';
|
| 539 |
+
shareBtn.disabled = true;
|
| 540 |
+
|
| 541 |
+
try {
|
| 542 |
+
// Capture specific area
|
| 543 |
+
const captureElement = document.getElementById('result-capture-area');
|
| 544 |
+
|
| 545 |
+
// Temporarily add a background to the capture area for a better image
|
| 546 |
+
const originalBg = captureElement.style.backgroundColor;
|
| 547 |
+
captureElement.style.backgroundColor = '#0f172a'; // Dark blue bg
|
| 548 |
+
captureElement.style.padding = '20px'; // Add padding for screenshot
|
| 549 |
+
|
| 550 |
+
// Wait for image to load before capturing
|
| 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 |
|
| 565 |
+
// Restore styles
|
| 566 |
+
captureElement.style.backgroundColor = originalBg;
|
| 567 |
+
captureElement.style.padding = '';
|
| 568 |
+
|
| 569 |
+
// Convert to Blob
|
| 570 |
+
canvas.toBlob(async (blob) => {
|
| 571 |
+
if (!blob) {
|
| 572 |
+
alert('截圖生成失敗,請檢查網路連線或使用原生截圖功能。');
|
| 573 |
+
shareBtn.innerHTML = originalContent;
|
| 574 |
+
shareBtn.disabled = false;
|
| 575 |
+
return;
|
| 576 |
+
}
|
| 577 |
+
|
| 578 |
+
const file = new File([blob], 'gamified-teaching-result.png', { type: 'image/png' });
|
| 579 |
+
|
| 580 |
+
// Mobile Native Share (Web Share API Level 2)
|
| 581 |
+
if (navigator.canShare && navigator.canShare({ files: [file] })) {
|
| 582 |
+
try {
|
| 583 |
+
await navigator.share({
|
| 584 |
+
files: [file],
|
| 585 |
+
title: '遊戲化教學天賦覺醒',
|
| 586 |
+
text: `我是『${this.resultsData[this.currentWinnerKey].title}』!測測看你是哪種角色:`
|
| 587 |
+
});
|
| 588 |
+
} catch (err) {
|
| 589 |
+
console.log('Share cancelled or failed', err);
|
| 590 |
+
}
|
| 591 |
+
} else {
|
| 592 |
+
// Fallback for Desktop: Download
|
| 593 |
+
const link = document.createElement('a');
|
| 594 |
+
link.download = `teaching-style-${this.currentWinnerKey}.png`;
|
| 595 |
+
link.href = canvas.toDataURL();
|
| 596 |
+
link.click();
|
| 597 |
+
alert('您的裝置不支援直接圖片分享,已為您下載結果圖片!您現在可以手動發送到 Line 或 IG。');
|
| 598 |
+
}
|
| 599 |
+
|
| 600 |
+
// Restore Button
|
| 601 |
+
shareBtn.innerHTML = originalContent;
|
| 602 |
+
shareBtn.disabled = false;
|
| 603 |
+
}, 'image/png');
|
| 604 |
+
|
| 605 |
+
} catch (error) {
|
| 606 |
+
console.error('Error generating image:', error);
|
| 607 |
+
alert('圖片生成失敗,可能是因為圖片伺服器限制了存取。請嘗試使用手機的原生截圖功能分享!');
|
| 608 |
+
shareBtn.innerHTML = originalContent;
|
| 609 |
+
shareBtn.disabled = false;
|
| 610 |
+
}
|
| 611 |
}
|
| 612 |
};
|
| 613 |
|