-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
407 lines (356 loc) · 11.6 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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>我的IP</title>
<link rel="stylesheet" href="components/message_ui.css">
<style>
table {
border-collapse: collapse;
width: 90%;
margin-left: 5%;
height: 300px;
border-radius: 10%;
}
tr {
border-bottom: 1px solid #bdbdbd;
height: 30px;
}
tr td {
width: 24%;
}
.cont {
border: 1px solid #bdbdbd;
width: 80%;
margin-left: 10%;
border-radius: .25rem;
box-shadow: 0 4px 6px -1px #0000001a, 0 2px 4px -1px #0000000f;
}
.ip {
width: 20%;
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, monospace;
}
.ip span {
margin-left: 5px;
}
.lab {
padding-left: 15px;
font-size: large;
font-weight: 400;
width: 10%;
}
.lab {
color: #000000;
}
.des {
color: cadetblue;
}
.copy {
background-image: url('assets/copy.svg');
background-repeat: no-repeat;
padding-left: 20px;
cursor: pointer;
}
.speed_test_cont {
margin-top: 20px;
display: flex;
flex-flow: row wrap;
justify-content: space-evenly;
align-items: stretch;
flex-wrap: wrap;
}
.stc_item {
flex-basis: calc(100% / 5);
border: 1px solid #e4e4e4;
box-shadow: 0 4px 6px -1px #0000001a, 0 2px 4px -1px #0000000f;
margin-bottom: 1.2rem;
}
.st_title {
width: 100%;
text-align: center;
font-size: 1.25rem;
font-weight: 400;
}
.st_des {
width: 100%;
text-align: center;
font-size: 0.85rem;
color: #a2a2a2;
}
.st_time {
width: 100%;
text-align: center;
font-size: 1.10rem;
color: #009800cc;
}
.speed_test_cont hr {
width: 80%;
}
.dns_info_cont {
margin-top: 10px;
height: 10rem;
}
.dic_title {
width: 20%;
font-weight: 500;
color: darkcyan;
}
.dic_ip {
width: 30%;
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, monospace;
}
.dic_geo {
width: 50%;
color: #6b7280;
}
@media (prefers-color-scheme: dark) {
.ip {
color: #c6c6c6;
}
.lab {
color: #7d7d7d;
}
#loc {
color: #7d7d7d;
}
.st_title {
color: #40a7b1;
}
.dic_ip {
color: #c6c6c6;
}
.dic_geo {
color: #7d7d7d;
}
}
</style>
</head>
<body>
<div class="cont">
<table>
<tbody>
<tr>
<td class="lab">内网</td>
<td class="ip">
<span id="lanIpv4">0.0.0.0</span>
<span class="copy" onclick="copyLan()" title="复制"></span></td>
<td class="des">已复制到剪贴板</td>
<td></td>
</tr>
<tr>
<td class="lab">公网</td>
<td class="ip">
<span id="ip_1">0.0.0.0</span>
<span class="copy" onclick="copyIp1()" title="复制"></span>
</td>
<td class="des"><span id="address1"></span></td>
<td class="des"><span id="net_str1"></span></td>
</tr>
<tr>
<td class="lab">代理</td>
<td class="ip">
<span id="ip_2">0.0.0.0</span>
<span class="copy" onclick="copyIp2()" title="复制"></span>
</td>
<td class="des"><span id="address2"></span></td>
<td class="des"><span id="net_str2"></span></td>
</tr>
<tr style="border: none">
<td class="lab">位置</td>
<td id="loc" colspan="2">定位中...</td>
<td></td>
</tr>
</tbody>
</table>
</div>
<div class="cont" style="margin-top: 15px">
<div class="speed_test_cont" id="speed_test_cont"></div>
</div>
<div class="cont" style="margin-top: 15px">
<table class="dns_info_cont" id="dns_info_cont">
</table>
</div>
<div class="parent-tips" style="display: block; z-index: 1113;">
<div class="global-msg-tips info">
</div>
</div>
</body>
<script type="text/javascript">
utools.onPluginEnter(({code, type, payload}) => {
// 获取内网地址
window.lanIPv4((ip) => {
document.getElementById("lanIpv4").innerText = ip;
utools.copyText(ip);
});
// 获取地理信息
window.locationInfo((address) => {
document.getElementById("loc").innerText = address;
}, function (error) {
console.error(error);
});
// 获取外网地址1
window.wan_no_proxy((data) => {
document.getElementById("ip_1").innerText = data.ip;
document.getElementById("address1").innerText = data.addr;
document.getElementById("net_str1").innerText = data.net_str;
}, function (error) {
document.getElementById("ip_1").innerText = error;
console.error(error);
});
// 获取外网地址2
window.wan_has_proxy((data) => {
document.getElementById("ip_2").innerText = data.ip;
document.getElementById("address2").innerText = data.addr;
document.getElementById("net_str2").innerText = data.net_str;
}, function (error) {
document.getElementById("ip_2").innerText = error;
console.error(error);
});
// 开始测速组件
let array = [{
url: "https://www.baidu.com",
name: "百度搜索",
des: "境内网站",
id: "1"
}, {
url: "https://music.163.com",
name: "网易云",
des: "境内网站",
id: "2"
}, {
url: "https://github.com",
name: "GitHub",
des: "境外网站",
id: "3"
}, {
url: "https://google.com",
name: "Google",
des: "境外网站",
id: "4"
}, {
url: "https://www.aliyun.com",
name: "阿里云",
des: "境内网站",
id: "5"
}, {
url: "https://cloud.tencent.com",
name: "腾讯云",
des: "境内网站",
id: "6"
}, {
url: "https://youtube.com",
name: "Youtube",
des: "境外网站",
id: "7"
}, {
url: "https://www.amazon.com",
name: "亚马逊",
des: "境外网站",
id: "8"
}
];
testNetDelay(array);
// DNS出口查询
dnsExitQuery();
})
function copyLan() {
utools.copyText(document.getElementById("lanIpv4").innerText)
confetti();
}
function copyIp1() {
utools.copyText(document.getElementById("ip_1").innerText)
confetti();
}
function copyIp2() {
utools.copyText(document.getElementById("ip_2").innerText)
confetti();
}
// 测延迟
function testNetDelay(array) {
document.getElementById("speed_test_cont").innerHTML = "";
// 创建dom
array.forEach(e => {
// 创建div元素
let div = document.createElement("div");
div.classList.add("stc_item");
let pTitle = document.createElement("p");
pTitle.classList.add("st_title");
pTitle.innerText = e.name;
let pDes = document.createElement("p");
pDes.classList.add("st_des");
pDes.innerText = e.des;
let hr = document.createElement("hr");
let pTime = document.createElement("p");
pTime.innerText = "测速中...";
pTime.classList.add("st_time");
pTime.id = "st_time_item_" + e.id;
div.appendChild(pTitle);
div.appendChild(pDes);
div.appendChild(hr);
div.appendChild(pTime);
document.getElementById("speed_test_cont").appendChild(div);
});
let startTime = new Date().getTime();
array.forEach(function (element) {
fetch(element.url).then(r => {
let endTime = new Date().getTime();
let latency = endTime - startTime;
if (latency > 1000) {
document.getElementById("st_time_item_" + element.id).style.color = "origin";
}
if (latency > 3000) {
document.getElementById("st_time_item_" + element.id).style.color = "yellow";
}
if (latency > 7000) {
document.getElementById("st_time_item_" + element.id).style.color = "red";
}
document.getElementById("st_time_item_" + element.id).innerText = latency + "ms"
}).catch(function (error) {
document.getElementById("st_time_item_" + element.id).innerText = "❌";
document.getElementById("st_time_item_" + element.id).style.color = "red";
console.error(error);
});
});
}
// DNS出口查询
function dnsExitQuery(){
document.getElementById("dns_info_cont").innerHTML = "";
for (let i = 0; i < 4; i++) {
fetch("https://"+generateRandomString(32)+".edns.ip-api.com/json?lang=zh-CN").then(response => {
console.log(response);
response.json().then((res) => {
let tr = document.createElement("tr");
let td1 = document.createElement("td");
td1.className = "dic_title";
td1.textContent = "DNS out";
let td2 = document.createElement("td");
td2.className = "dic_ip";
td2.textContent = res.dns.ip;
let td3 = document.createElement("td");
td3.className = "dic_geo";
td3.textContent = res.dns.geo;
tr.appendChild(td1);
tr.appendChild(td2);
tr.appendChild(td3);
document.getElementById("dns_info_cont").appendChild(tr);
}).catch(e => {
console.error(e);
});
}).catch(error => {
console.error(error);
});
}
function generateRandomString(length) {
let characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let result = '';
for (let i = 0; i < length; i++) {
let randomIndex = Math.floor(Math.random() * characters.length);
result += characters.charAt(randomIndex);
}
return result;
}
}
</script>
<!--showToast("复制成功", "success")-->
<!--<script type="application/javascript" src="components/message_ui.js"></script>-->
</html>