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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="zh-Hant">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>即時互動文字雲 - 參與者</title>
|
| 7 |
+
<style>
|
| 8 |
+
* { box-sizing: border-box; margin: 0; padding: 0; }
|
| 9 |
+
body {
|
| 10 |
+
font-family: 'Noto Sans TC', 'Microsoft JhengHei', sans-serif;
|
| 11 |
+
background: linear-gradient(160deg, #FEF3C7, #FFEDD5);
|
| 12 |
+
min-height: 100vh; display: flex; align-items: center; justify-content: center;
|
| 13 |
+
padding: 20px;
|
| 14 |
+
}
|
| 15 |
+
.card {
|
| 16 |
+
background: #fff; padding: 36px 40px; border-radius: 24px;
|
| 17 |
+
width: 100%; max-width: 460px;
|
| 18 |
+
box-shadow: 0 20px 50px rgba(0,0,0,.12); text-align: center;
|
| 19 |
+
}
|
| 20 |
+
h1 { color: #F97316; font-size: 24px; margin-bottom: 6px; }
|
| 21 |
+
.sub { color: #64748B; font-size: 14px; margin-bottom: 26px; }
|
| 22 |
+
|
| 23 |
+
label { display: block; text-align: left; font-size: 14px; color: #475569; margin-bottom: 6px; }
|
| 24 |
+
input[type=text] {
|
| 25 |
+
width: 100%; padding: 11px 13px; font-size: 16px;
|
| 26 |
+
border: 1px solid #FDBA74; border-radius: 10px; outline: none; margin-bottom: 20px;
|
| 27 |
+
}
|
| 28 |
+
input:focus { border-color: #F97316; }
|
| 29 |
+
.btn {
|
| 30 |
+
width: 100%; padding: 12px; font-size: 17px; font-weight: 700;
|
| 31 |
+
border: none; border-radius: 12px; background: #F97316; color: #fff; cursor: pointer;
|
| 32 |
+
}
|
| 33 |
+
.btn:disabled { background: #CBD5E1; cursor: not-allowed; }
|
| 34 |
+
|
| 35 |
+
/* 加入後的輸入狀態 */
|
| 36 |
+
#input-section { display: none; }
|
| 37 |
+
#question-display {
|
| 38 |
+
display: none; background: #FFF7ED; border: 1px solid #FED7AA; border-radius: 12px;
|
| 39 |
+
padding: 12px 15px; margin-bottom: 22px; font-size: 16px; color: #9A3412;
|
| 40 |
+
}
|
| 41 |
+
#lock-notice {
|
| 42 |
+
display: none; background: #FEE2E2; border: 1px solid #FECACA; color: #991B1B;
|
| 43 |
+
border-radius: 12px; padding: 12px; margin-bottom: 22px; font-size: 15px;
|
| 44 |
+
}
|
| 45 |
+
#you-sent {
|
| 46 |
+
display: block; margin-top: 16px; font-size: 13px; color: #16A34A; min-height: 18px;
|
| 47 |
+
}
|
| 48 |
+
#id-suffix { margin-top: 14px; font-size: 12px; color: #94A3B8; }
|
| 49 |
+
</style>
|
| 50 |
+
</head>
|
| 51 |
+
<body>
|
| 52 |
+
|
| 53 |
+
<div class="card" id="join-card">
|
| 54 |
+
<h1>☁️ 互動文字雲</h1>
|
| 55 |
+
<div class="sub">加入並送出你的想法</div>
|
| 56 |
+
|
| 57 |
+
<!-- 加入階段 -->
|
| 58 |
+
<div id="join-section">
|
| 59 |
+
<label>輸入房間代碼</label>
|
| 60 |
+
<input type="text" id="room-input" maxlength="4" placeholder="例:1234" inputmode="numeric">
|
| 61 |
+
<button class="btn" id="btn-join">加入</button>
|
| 62 |
+
</div>
|
| 63 |
+
|
| 64 |
+
<!-- 已加入,送詞彙 -->
|
| 65 |
+
<div id="input-section">
|
| 66 |
+
<div id="question-display"></div>
|
| 67 |
+
<div id="lock-notice">🔒 老師已暫停接收詞彙,請稍候。</div>
|
| 68 |
+
<label>輸入你的詞彙 / 想法</label>
|
| 69 |
+
<input type="text" id="word-input" placeholder="輸入詞彙或 $數學式$…" autocomplete="off">
|
| 70 |
+
<button class="btn" id="btn-send">送出</button>
|
| 71 |
+
<span id="you-sent"></span>
|
| 72 |
+
<div id="id-suffix"></div>
|
| 73 |
+
</div>
|
| 74 |
+
</div>
|
| 75 |
+
|
| 76 |
+
<script type="module">
|
| 77 |
+
import { initializeApp } from 'https://www.gstatic.com/firebasejs/10.12.2/firebase-app.js';
|
| 78 |
+
import { getFirestore, doc, getDoc, onSnapshot, updateDoc, increment } from 'https://www.gstatic.com/firebasejs/10.12.2/firebase-firestore.js';
|
| 79 |
+
|
| 80 |
+
const firebaseConfig = {
|
| 81 |
+
ApiKey: "AIzaSyAcIQYst9gFRyE2nCqCwNgCL3LG2VkBXbM",
|
| 82 |
+
authDomain: "factor-529c9.firebaseapp.com",
|
| 83 |
+
projectId: "factor-529c9",
|
| 84 |
+
storageBucket: "factor-529c9.firebasestorage.app",
|
| 85 |
+
messagingSenderId: "575829635896",
|
| 86 |
+
appId: "1:575829635896:web:a65b6edd9d163375b087cd"
|
| 87 |
+
};
|
| 88 |
+
|
| 89 |
+
const app = initializeApp(firebaseConfig);
|
| 90 |
+
const db = getFirestore(app);
|
| 91 |
+
|
| 92 |
+
let roomCode = null;
|
| 93 |
+
let roomRef = null;
|
| 94 |
+
let participantId = Date.now().toString(36);
|
| 95 |
+
|
| 96 |
+
const qs = new URLSearchParams(location.search);
|
| 97 |
+
const qRoom = qs.get('room');
|
| 98 |
+
if (qRoom) { document.getElementById('room-input').value = qRoom; join(); }
|
| 99 |
+
|
| 100 |
+
// ---- 加入 ----
|
| 101 |
+
document.getElementById('btn-join').addEventListener('click', join);
|
| 102 |
+
async function join() {
|
| 103 |
+
const value = document.getElementById('room-input').value.trim();
|
| 104 |
+
if (!/^\d{4}$/.test(value)) { alert('請輸入 4 位數房間代碼'); return; }
|
| 105 |
+
roomCode = value;
|
| 106 |
+
roomRef = doc(db, 'rooms', roomCode);
|
| 107 |
+
const snap = await getDoc(roomRef);
|
| 108 |
+
if (!snap.exists()) { alert('找不到此房間,請確認代碼'); return; }
|
| 109 |
+
|
| 110 |
+
document.getElementById('join-section').style.display = 'none';
|
| 111 |
+
document.getElementById('input-section').style.display = 'block';
|
| 112 |
+
document.getElementById('id-suffix').textContent = '參與者代號:' + participantId;
|
| 113 |
+
initListeners();
|
| 114 |
+
initInput();
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
// ---- 監聽房間狀態 ----
|
| 118 |
+
function initListeners() {
|
| 119 |
+
onSnapshot(roomRef, (snap) => {
|
| 120 |
+
const data = snap.data();
|
| 121 |
+
if (!data) return;
|
| 122 |
+
const qEl = document.getElementById('question-display');
|
| 123 |
+
if (data.question) { qEl.textContent = '📌 ' + data.question; qEl.style.display = 'block'; }
|
| 124 |
+
else { qEl.style.display = 'none'; }
|
| 125 |
+
|
| 126 |
+
const locked = data.locked || false;
|
| 127 |
+
document.getElementById('lock-notice').style.display = locked ? 'block' : 'none';
|
| 128 |
+
document.getElementById('word-input').disabled = locked;
|
| 129 |
+
document.getElementById('btn-send').disabled = locked;
|
| 130 |
+
});
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
// ---- 送出詞彙 ----
|
| 134 |
+
function initInput() {
|
| 135 |
+
document.getElementById('btn-send').addEventListener('click', submit);
|
| 136 |
+
document.getElementById('word-input').addEventListener('keydown', e => {
|
| 137 |
+
if (e.key === 'Enter') submit();
|
| 138 |
+
});
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
async function submit() {
|
| 142 |
+
const word = document.getElementById('word-input').value.trim();
|
| 143 |
+
if (!word) return;
|
| 144 |
+
|
| 145 |
+
const snap = await getDoc(roomRef);
|
| 146 |
+
const data = snap.data();
|
| 147 |
+
if (data.locked) { alert('老師已鎖定,暫停接收'); return; }
|
| 148 |
+
|
| 149 |
+
// 多重送出關閉時,避免重複送出同一詞(可依需求調整)
|
| 150 |
+
const alreadySent = data.sentBy && data.sentBy[participantId];
|
| 151 |
+
if (!data.allowMultiple && alreadySent) {
|
| 152 |
+
alert('您已送出過詞彙,老師未開啟多次送出。');
|
| 153 |
+
return;
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
await updateDoc(roomRef, {
|
| 157 |
+
[`words.${word}`]: increment(1),
|
| 158 |
+
[`sentBy.${participantId}`]: true // 記錄已送出
|
| 159 |
+
});
|
| 160 |
+
|
| 161 |
+
document.getElementById('you-sent').textContent = '已送出:「' + word + '」✓';
|
| 162 |
+
document.getElementById('word-input').value = '';
|
| 163 |
+
}
|
| 164 |
+
</script>
|
| 165 |
+
|
| 166 |
+
<script>
|
| 167 |
+
window.MathJax = {
|
| 168 |
+
tex: { inlineMath: [['$','$'],['\\(','\\)']], displayMath: [['$$','$$'],['\\[','\\]']], processEscapes: true },
|
| 169 |
+
options: { skipHtmlTags: ['script','noscript','style','textarea','pre'] }
|
| 170 |
+
};
|
| 171 |
+
</script>
|
| 172 |
+
<script async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script>
|
| 173 |
+
|
| 174 |
+
</body>
|
| 175 |
+
</html>
|