-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRankingu_kai.html
More file actions
183 lines (158 loc) · 5.85 KB
/
Rankingu_kai.html
File metadata and controls
183 lines (158 loc) · 5.85 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8" />
<title>Time Attack Ranking</title>
<!-- React / Babel / Tailwind -->
<script src="https://unpkg.com/react@18/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<script src="https://cdn.tailwindcss.com"></script>
<!-- Google Font -->
<link
href="https://fonts.googleapis.com/css2?family=M+PLUS+Rounded+1c:wght@500&display=swap"
rel="stylesheet"
/>
<style>
body {
font-family: "M PLUS Rounded 1c", sans-serif;
}
</style>
</head>
<body class="bg-gradient-to-br from-green-100 via-emerald-200 to-green-50 flex items-center justify-center min-h-screen">
<div id="root"></div>
<!-- ✅ app.jsの内容をここに直接貼る -->
<script type="text/babel">
const { useState, useRef } = React;
function RankingApp() {
// ✅ 全員のデータを保持する配列
const [allRecords, setAllRecords] = useState([]);
const [name, setName] = useState("");
const [time, setTime] = useState("");
const nameRef = useRef(null);
const timeRef = useRef(null);
const handleAdd = () => {
if (!name || !time) return;
// ✅ 現在時刻を追加
const timestamp = new Date().toLocaleString("ja-JP", { hour12: false });
const newRecord = { name, time: parseFloat(time), date: timestamp };
// 全データを更新(消さない)
const updatedAll = [...allRecords, newRecord];
setAllRecords(updatedAll);
// 入力リセット
setName("");
setTime("");
nameRef.current.focus();
};
const handleTimeChange = (e) => {
const value = e.target.value;
const half = value.replace(/[0-9.]/g, (s) =>
String.fromCharCode(s.charCodeAt(0) - 0xfee0)
);
setTime(half);
};
// ✅ 表示用(上位5名だけ)
const records = [...allRecords].sort((a, b) => a.time - b.time).slice(0, 5);
// ✅ CSVエクスポート(全員分)
const exportCSV = () => {
const sorted = [...allRecords].sort((a, b) => a.time - b.time);
const csv =
"順位,名前,タイム(秒),記録日時\n" +
sorted
.map((r, i) => `${i + 1},${r.name},${r.time.toFixed(2)},${r.date}`)
.join("\n");
const blob = new Blob([csv], { type: "text/csv" });
const url = window.URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = "ranking.csv";
a.click();
};
const handleKeyDown = (e, field) => {
if (e.key === "Enter") {
if (field === "name") timeRef.current.focus();
else handleAdd();
} else if (e.key === "ArrowRight") {
if (field === "name") timeRef.current.focus();
} else if (e.key === "ArrowLeft") {
if (field === "time") nameRef.current.focus();
}
};
const avg = records.length
? (records.reduce((sum, r) => sum + r.time, 0) / records.length).toFixed(2)
: "-";
const best = records.length
? Math.min(...records.map((r) => r.time)).toFixed(2)
: "-";
return (
<div
className="flex flex-col items-center justify-center min-h-screen w-full text-green-900"
style={{
background: "linear-gradient(135deg, #c8f7dc 0%, #e2f9f1 100%)",
fontFamily: "'M PLUS Rounded 1c', sans-serif",
padding: "20px",
}}
>
<div className="max-w-[1200px] min-h-[600px] bg-white/30 backdrop-blur-lg rounded-3xl shadow-2xl border border-white/20 flex flex-col justify-start items-center p-12">
<h1 className="text-4xl font-bold mb-6"> タイムアタックランキング! </h1>
<ul className="w-full mb-4">
{[0, 1, 2, 3, 4].map((i) => (
<li
key={i}
className="flex justify-between border-b py-2 text-xl font-medium"
>
<span>{i + 1}位</span>
<span>{records[i]?.name || "ーーー"}</span>
<span>
{records[i]?.time ? records[i].time.toFixed(2) + "秒" : "ーーー"}
</span>
</li>
))}
</ul>
<p className="mb-4">
最高タイム:{best}秒 平均タイム:{avg}秒
</p>
<div className="w-full flex flex-col gap-4 mb-6">
<input
ref={nameRef}
id="nameInput"
type="text"
placeholder="プレイヤー名"
value={name}
onChange={(e) => setName(e.target.value)}
onKeyDown={(e) => handleKeyDown(e, "name")}
className="p-3 border rounded-lg text-lg w-full"
/>
<input
ref={timeRef}
id="timeInput"
type="text"
placeholder="タイム(秒)"
value={time}
onChange={handleTimeChange}
onKeyDown={(e) => handleKeyDown(e, "time")}
className="p-3 border rounded-lg text-lg w-full"
/>
<button
onClick={handleAdd}
className="bg-green-500 text-white rounded-lg py-2 hover:bg-green-600 transition"
>
登録
</button>
</div>
<p>参加人数:{allRecords.length}人</p>
</div>
<button
onClick={exportCSV}
className="fixed bottom-4 right-4 text-xs bg-gray-300/50 hover:bg-gray-400/70 text-gray-800 px-3 py-1 rounded-lg shadow-md transition"
>
CSV保存
</button>
</div>
);
}
const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(<RankingApp />);
</script>
</body>
</html>