Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
158 lines (150 loc) · 4.4 KB
/
Copy pathindex.html
File metadata and controls
158 lines (150 loc) · 4.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<!DOCTYPE html>
<html lang="zh-TW">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>文字雲 — 輸入頁</title>
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background: #0f172a;
font-family: 'Noto Sans TC', sans-serif;
padding: 24px;
}
h1 {
color: #f1f5f9;
font-size: 1.8rem;
margin-bottom: 8px;
text-align: center;
}
p.subtitle {
color: #94a3b8;
margin-bottom: 32px;
text-align: center;
font-size: 1rem;
}
.card {
background: #1e293b;
border-radius: 16px;
padding: 32px;
width: 100%;
max-width: 480px;
box-shadow: 0 4px 32px rgba(0,0,0,0.4);
}
input[type="text"] {
width: 100%;
padding: 14px 16px;
font-size: 1.2rem;
border-radius: 10px;
border: 2px solid #334155;
background: #0f172a;
color: #f1f5f9;
outline: none;
transition: border-color 0.2s;
text-align: center;
}
input[type="text"]:focus {
border-color: #6366f1;
}
button {
margin-top: 16px;
width: 100%;
padding: 14px;
font-size: 1.1rem;
font-weight: bold;
background: #6366f1;
color: white;
border: none;
border-radius: 10px;
cursor: pointer;
transition: background 0.2s, transform 0.1s;
}
button:hover { background: #4f46e5; }
button:active { transform: scale(0.98); }
button:disabled { background: #475569; cursor: not-allowed; }
.message {
margin-top: 20px;
text-align: center;
font-size: 1rem;
min-height: 24px;
}
.message.success { color: #34d399; }
.message.error { color: #f87171; }
.cloud-link {
margin-top: 24px;
text-align: center;
}
.cloud-link a {
color: #818cf8;
text-decoration: none;
font-size: 0.9rem;
}
.cloud-link a:hover { text-decoration: underline; }
</style>
</head>
<body>
<h1>📝 請輸入一個詞</h1>
<p class="subtitle">你的詞會即時出現在文字雲上</p>
<div class="card">
<input type="text" id="wordInput" placeholder="輸入詞語" maxlength="20" autocomplete="off" />
<button id="submitBtn" onclick="submitWord()">送出</button>
<div class="message" id="message"></div>
<div class="cloud-link">
<a href="cloud.html" target="_blank">📊 查看即時文字雲 →</a>
</div>
</div>
<script type="module">
import { initializeApp } from 'https://www.gstatic.com/firebasejs/10.12.0/firebase-app.js';
import { getFirestore, collection, addDoc, serverTimestamp }
from 'https://www.gstatic.com/firebasejs/10.12.0/firebase-firestore.js';
const firebaseConfig = {
apiKey: "AIzaSyDOyazYCHo0oE-1d-1-5Ii1UMCodb7Rfr8",
authDomain: "diy-work-af63e.firebaseapp.com",
projectId: "diy-work-af63e",
storageBucket: "diy-work-af63e.firebasestorage.app",
messagingSenderId: "300082462154",
appId: "1:300082462154:web:a39a1084e304622d1ee333"
};
const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
window.submitWord = async function () {
const input = document.getElementById('wordInput');
const btn = document.getElementById('submitBtn');
const msgEl = document.getElementById('message');
const word = input.value.trim();
if (!word) {
msgEl.className = 'message error';
msgEl.textContent = '請輸入詞語';
return;
}
btn.disabled = true;
msgEl.className = 'message';
msgEl.textContent = '送出中…';
try {
await addDoc(collection(db, 'wordcloud_words'), {
word,
timestamp: serverTimestamp()
});
msgEl.className = 'message success';
msgEl.textContent = `✅ 「${word}」已送出!`;
input.value = '';
} catch (e) {
msgEl.className = 'message error';
msgEl.textContent = '送出失敗,請再試一次';
console.error(e);
} finally {
btn.disabled = false;
input.focus();
}
};
document.getElementById('wordInput').addEventListener('keydown', e => {
if (e.key === 'Enter') window.submitWord();
});
</script>
</body>
</html>