-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
318 lines (294 loc) · 11.5 KB
/
index.html
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
<!DOCTYPE html>
<html lang="zh-CN">
<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, html {
height: 100%;
overflow: hidden;
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
}
#main-container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-start; /* 从顶部开始对齐 */
height: 100%;
width: 100%;
padding: 20px;
overflow-y: auto;
scroll-behavior: smooth;
}
#welcome-info {
user-select: none;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: 90vw;
max-width: 400px;
padding: 20px;
border-radius: 12px;
background-color: #ffffff;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
outline: 1px solid #dcdcdc;
text-align: center;
margin-bottom: 10px;
}
.welcome-header {
font-size: 1.4rem;
font-weight: bold;
color: #ff4c4c;
margin-bottom: 10px;
display: flex;
align-items: center;
}
.intro {
font-size: 1rem;
margin-bottom: 15px;
text-align: left;
line-height: 1.8;
display: flex;
flex-direction: column;
align-items: flex-start;
}
.intro .item {
display: flex;
align-items: center;
margin-bottom: 6px;
}
.intro .icon {
margin-right: 8px;
font-size: 1.2rem;
}
.intro .highlight {
color: #007bff;
font-weight: bold;
}
.intro a {
color: #007bff;
text-decoration: none;
}
.intro a:hover {
text-decoration: underline;
}
.welcome-message {
background-color: #e7f3ff;
border: 1px solid #b0d4f1;
padding: 15px;
border-radius: 8px;
margin-top: 20px;
width: 100%;
box-sizing: border-box;
}
.welcome-message p {
margin: 8px 0;
line-height: 1.5;
}
.ip-address {
filter: blur(5px);
transition: filter 0.3s ease;
}
.ip-address:hover {
filter: blur(0);
}
.loading-spinner {
width: 40px;
height: 40px;
border: 4px solid rgba(0, 0, 0, 0.1);
border-radius: 50%;
border-top: 4px solid #4CAF50;
animation: spin 1s linear infinite;
margin-bottom: 10px;
}
/* 错误信息样式 */
.error-message {
color: #ff6565;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.error-icon {
font-size: 6vw; /* 设置为视口单位大小 */
margin-bottom: 10px;
}
#error-message {
font-size: 4vw; /* 错误信息字体 */
margin-bottom: 15px;
}
#retry-button {
padding: 10px 20px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;
font-size: 3vw;
cursor: pointer;
}
#retry-button:hover {
background-color: #388E3C;
}
.github-link {
font-size: 1.2rem;
color: #333;
text-decoration: none;
display: flex;
align-items: center;
justify-content: center;
margin-top: 20px;
}
.github-link img {
width: 20px;
height: 20px;
margin-right: 5px;
}
.github-link:hover {
color: #000;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
</style>
</head>
<body>
<div id="main-container">
<div id="welcome-info">
<div class="welcome-header">
<span>📢</span> 欢迎来访者!
</div>
<div class="intro">
<div class="item"><span class="icon">👋</span>Hi,我是 <span class="highlight" id="blogger-name"></span>,欢迎你!</div>
<div class="item"><span class="icon">❓</span>如有问题欢迎评论区交流!</div>
<div class="item"><span class="icon">😡</span>页面异常?尝试 <strong>Ctrl + F5</strong></div>
<div class="item"><span class="icon">📩</span>如需联系我:<a href="#" id="contact-email">发送邮件</a> 🚀</div>
</div>
<div class="loading-spinner" id="loading-spinner"></div>
<!-- 欢迎信息块 -->
<div class="welcome-message">
<p>欢迎来自 <b id="visitor-location"></b> 的小友💖</p>
<p>你当前距博主约 <b id="visitor-distance"></b> 公里!</p>
<p>你的IP地址:<b class="ip-address" id="visitor-ip"></b></p>
<p id="greeting-message"></p>
<p>Tip:<b id="tip-message"></b></p>
</div>
</div>
<!-- GitHub 链接,居中放置在内容下方 -->
<a href="https://github.com/BDTA-zky" target="_blank" class="github-link" id="github-link">
<img src="https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png" alt="GitHub Logo">
GitHub
</a>
</div>
<script>
// 配置参数
const CONFIG = {
BLOGGER_NAME: 'BUZZ', // 博主名字
EMAIL: 'mailto:[email protected]', // 博主的联系邮箱链接
GITHUB_URL: 'https://github.com/BDTA-zky', // 博主的 GitHub 链接
API_KEY: '4xR95RXijydgvLwXDmINz8ebaq', // API 密钥,请求 IP 信息用
BLOG_LOCATION: { lng: 113.506990, lat: 34.704587 }, // 博主的位置经纬度
CACHE_DURATION: 1000 * 60 * 60, // 缓存时间(默认1小时)
HOME_PAGE_ONLY: true, // 是否只在首页显示
};
// 设置博主信息
document.getElementById('blogger-name').textContent = CONFIG.BLOGGER_NAME;
document.getElementById('contact-email').href = CONFIG.EMAIL;
document.getElementById('github-link').href = CONFIG.GITHUB_URL;
const fetchIpData = async () => {
try {
const response = await fetch(`https://api.76.al/api/ip/query?key=${encodeURIComponent(CONFIG.API_KEY)}`);
if (!response.ok) {
console.error('Response Error:', response.status, response.statusText);
throw new Error(`网络响应不正常: ${response.status} ${response.statusText}`);
}
return await response.json();
} catch (error) {
console.error('Fetch IP Data Error:', error);
throw new Error('无法获取IP信息,请检查网络连接或API配置');
}
};
const showWelcome = ({ data, ip }) => {
document.getElementById('loading-spinner').style.display = 'none';
if (!data) return showErrorMessage();
const { lng, lat, country, prov, city } = data;
const dist = calculateDistance(lng, lat);
const ipDisplay = formatIpDisplay(ip);
const pos = formatLocation(country, prov, city);
document.getElementById('visitor-location').textContent = pos;
document.getElementById('visitor-distance').textContent = dist;
document.getElementById('visitor-ip').textContent = ipDisplay;
document.getElementById('greeting-message').textContent = getTimeGreeting();
document.getElementById('tip-message').textContent = getGreeting(country, prov, city);
};
const calculateDistance = (lng, lat) => {
const R = 6371;
const rad = Math.PI / 180;
const dLat = (lat - CONFIG.BLOG_LOCATION.lat) * rad;
const dLon = (lng - CONFIG.BLOG_LOCATION.lng) * rad;
const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
Math.cos(CONFIG.BLOG_LOCATION.lat * rad) * Math.cos(lat * rad) *
Math.sin(dLon / 2) * Math.sin(dLon / 2);
return Math.round(R * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)));
};
const formatIpDisplay = (ip) => ip.includes(":") ? "复杂的IPv6地址" : ip;
const formatLocation = (country, prov, city) => country ? (country === "中国" ? `${prov} ${city}` : country) : '神秘地区';
const showErrorMessage = (message = '抱歉,无法获取信息') => {
document.getElementById('loading-spinner').style.display = 'none';
document.querySelector('.welcome-message').innerHTML = `
<div class="error-message">
<div class="error-icon">😕</div>
<p id="error-message">${message}</p>
<button id="retry-button">重试</button>
</div>
`;
// 给重试按钮绑定点击事件
document.getElementById('retry-button').addEventListener('click', () => {
document.getElementById('loading-spinner').style.display = 'block';
fetchIpInfo(); // 重新发起请求
});
};
const getTimeGreeting = () => {
const hour = new Date().getHours();
if (hour < 11) return "早上好🌤️ ,一日之计在于晨";
if (hour < 13) return "中午好☀️ ,记得午休喔~";
if (hour < 17) return "下午好🕞 ,饮茶先啦!";
if (hour < 19) return "即将下班🚶♂️,记得按时吃饭~";
return "晚上好🌙 ,夜生活嗨起来!";
};
const greetings = {
"中国": {
"河南省": { "郑州市": "豫州之域,天地之中", "其他": "河南欢迎你!" },
"其他": "中国欢迎你!"
},
"美国": "Let us live in peace!",
"其他": "带我去你的国家逛逛吧"
};
const getGreeting = (country, province, city) => {
const countryGreeting = greetings[country] || greetings["其他"];
if (typeof countryGreeting === 'string') return countryGreeting;
const provinceGreeting = countryGreeting[province] || countryGreeting["其他"];
return provinceGreeting[city] || provinceGreeting["其他"] || countryGreeting["其他"];
};
const fetchIpInfo = async () => {
try {
const data = await fetchIpData();
showWelcome(data);
} catch (error) {
showErrorMessage(error.message);
}
};
document.addEventListener('DOMContentLoaded', fetchIpInfo);
</script>
</body>
</html>