|
8 | 8 | <link rel="stylesheet" href="index.css"> |
9 | 9 | <script src="https://cdn.jsdelivr.net/npm/@unocss/runtime"></script> |
10 | 10 | </head> |
11 | | -<body class="bg-gray-900 text-white text-center p-4"> |
12 | | - <body class="bg-gray-900 text-white flex flex-col items-center justify-center min-h-screen font-sans p-4"> |
13 | | - <div class="flex flex-col md:flex-row items-center space-x-0 md:space-x-2 space-y-2 md:space-y-0"> |
14 | | - <div class="animate-spin text-4xl sm:text-5xl md:text-6xl">🌍</div> |
15 | | - <h1 class="text-2xl sm:text-3xl md:text-4xl font-bold">最新の地震情報</h1> |
16 | | - </div> |
| 11 | +<body class="bg-gray-900 text-white flex flex-col items-center justify-center min-h-screen font-sans p-4"> |
17 | 12 |
|
18 | | - <!-- 地震情報を表示するエリア --> |
19 | | - <div id="earthquake-info"> |
20 | | - <p>データ取得中...</p> |
| 13 | + <!-- ヘッダー部分 --> |
| 14 | + <div class="flex flex-col md:flex-row items-center space-x-0 md:space-x-2 space-y-2 md:space-y-0"> |
| 15 | + <div class="animate-spin text-4xl sm:text-5xl md:text-6xl">🌍</div> |
| 16 | + <h1 class="text-2xl sm:text-3xl md:text-4xl font-bold">最新の地震情報</h1> |
21 | 17 | </div> |
22 | 18 |
|
23 | | - <footer class="mt-6 text-sm opacity-70">Developer By Kaede</footer> |
| 19 | + <!-- 地震情報を表示するエリア --> |
| 20 | + <div id="earthquake-info" class="w-full max-w-md mt-4"></div> |
| 21 | + |
| 22 | + <footer class="mt-4 text-sm text-gray-400">Developer By Kaede</footer> |
24 | 23 |
|
25 | 24 | <script> |
26 | 25 | // 📌 震度の変換マップ |
@@ -48,59 +47,57 @@ <h1 class="text-2xl sm:text-3xl md:text-4xl font-bold">最新の地震情報</h1 |
48 | 47 | } |
49 | 48 | } |
50 | 49 |
|
| 50 | + // 📌 震度ごとのボーダーカラーを決定 |
| 51 | + function getBorderClass(intensity) { |
| 52 | + if (intensity >= 70) return "border-t-purple-500 border-b-purple-500"; // 震度7 |
| 53 | + if (intensity >= 60) return "border-t-red-500 border-b-red-500"; // 震度6 |
| 54 | + if (intensity >= 50) return "border-t-yellow-500 border-b-yellow-500"; // 震度5 |
| 55 | + return "border-t-gray-600 border-b-gray-600"; // 震度4以下 |
| 56 | + } |
| 57 | + |
51 | 58 | // 📌 地震情報を取得する関数 |
52 | 59 | function fetchEarthquakeInfo() { |
53 | 60 | fetch('https://api.p2pquake.net/v2/history?codes=551&limit=2') |
54 | 61 | .then(response => response.json()) |
55 | 62 | .then(data => { |
56 | 63 | const infoDiv = document.getElementById('earthquake-info'); |
57 | 64 | if (!data || data.length === 0) { |
58 | | - infoDiv.innerHTML = '<p>地震情報が見つかりませんでした。</p>'; |
| 65 | + infoDiv.innerHTML = '<p class="text-center">地震情報が見つかりませんでした。</p>'; |
59 | 66 | return; |
60 | 67 | } |
61 | 68 |
|
62 | | - // 最新の地震情報 |
63 | | - const latest = data[0]; |
64 | | - const previous = data[1] || null; |
65 | | - |
66 | | - function formatEarthquake(eq) { |
67 | | - if (!eq || !eq.earthquake) return '<p>情報なし</p>'; |
68 | | - const hypocenter = eq.earthquake.hypocenter?.name || '情報なし'; |
69 | | - const magnitude = eq.earthquake.hypocenter?.magnitude !== undefined |
70 | | - ? eq.earthquake.hypocenter.magnitude.toFixed(1) |
71 | | - : '情報なし'; |
72 | | - const maxIntensity = eq.earthquake.maxScale !== null |
73 | | - ? convertIntensity(eq.earthquake.maxScale) |
74 | | - : '情報なし'; |
75 | | - const time = eq.earthquake.time ? formatDateTime(eq.earthquake.time) : '情報なし'; |
| 69 | + let content = ""; |
| 70 | + data.forEach((earthquake, index) => { |
| 71 | + const hypocenter = earthquake.earthquake?.hypocenter?.name || '情報なし'; |
| 72 | + const magnitude = earthquake.earthquake?.hypocenter?.magnitude?.toFixed(1) || '情報なし'; |
| 73 | + const maxIntensity = earthquake.earthquake?.maxScale || 0; |
| 74 | + const time = earthquake.earthquake?.time || '情報なし'; |
| 75 | + const borderClass = getBorderClass(maxIntensity); |
76 | 76 |
|
77 | | - return ` |
78 | | - <div class="custom-card p-4 rounded-xl bg-white bg-opacity-10 backdrop-blur-md shadow-md my-4"> |
| 77 | + content += ` |
| 78 | + <div class="w-full max-w-md p-4 bg-gray-800 rounded-lg shadow-lg text-center my-2 border-4 ${borderClass}"> |
79 | 79 | <p><strong>震源地:</strong> ${hypocenter}</p> |
80 | 80 | <p><strong>マグニチュード:</strong> ${magnitude}</p> |
81 | | - <p><strong>最大震度:</strong> ${maxIntensity}</p> |
82 | | - <p><strong>発生日時:</strong> ${time}</p> |
| 81 | + <p><strong>最大震度:</strong> ${convertIntensity(maxIntensity)}</p> |
| 82 | + <p><strong>発生日時:</strong> ${formatDateTime(time)}</p> |
83 | 83 | </div> |
84 | 84 | `; |
85 | | - } |
| 85 | + }); |
86 | 86 |
|
87 | | - infoDiv.innerHTML = ` |
88 | | - <h2 class="text-xl font-bold">最新の地震</h2> |
89 | | - ${formatEarthquake(latest)} |
90 | | - ${previous ? `<h2 class="text-lg mt-6">一つ前の地震</h2>${formatEarthquake(previous)}` : ''} |
91 | | - `; |
| 87 | + infoDiv.innerHTML = content; |
92 | 88 | }) |
93 | 89 | .catch(error => { |
94 | 90 | console.error('エラー:', error); |
95 | | - document.getElementById('earthquake-info').innerHTML = '<p>データの取得に失敗しました。</p>'; |
| 91 | + document.getElementById('earthquake-info').innerHTML = '<p class="text-center">データの取得に失敗しました。</p>'; |
96 | 92 | }); |
97 | 93 | } |
98 | 94 |
|
99 | 95 | // 📌 初回データ取得 |
100 | 96 | fetchEarthquakeInfo(); |
101 | 97 |
|
102 | | - // 📌 5分ごと(300,000ミリ秒)にデータ更新 |
| 98 | + // 📌 5分ごとにデータ更新 |
103 | 99 | setInterval(fetchEarthquakeInfo, 300000); |
104 | 100 | </script> |
| 101 | + |
105 | 102 | </body> |
106 | 103 | </html> |
0 commit comments