-
Notifications
You must be signed in to change notification settings - Fork 5
/
script.js
133 lines (125 loc) · 5.88 KB
/
script.js
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
Vue.component('data-center', {
data: function () {
return {
loading: true,
coloInfo: null,
errorMessage: '',
darkMode: true,
ipAddress: null,
warpStatus: null,
tlsProtocol: null,
};
},
created: function () {
this.fetchDataCenterInfo();
this.applyDarkMode();
},
watch: {
darkMode: function () {
this.applyDarkMode();
}
},
methods: {
async fetchDataCenterInfo() {
try {
const colosDataResponse = await fetch('colos.json');
const colosData = await colosDataResponse.json();
const traceResponse = await fetch('https://www.cloudflare.com/cdn-cgi/trace');
const traceText = await traceResponse.text();
const traceLines = traceText.split('\n');
traceLines.forEach(line => {
const [key, value] = line.split('=');
switch (key) {
case 'colo':
if (colosData[value]) {
this.coloInfo = colosData[value];
} else {
this.errorMessage = 'No matching Cloudflare data centre information found';
}
break;
case 'ip':
this.ipAddress = value;
break;
case 'warp':
this.warpStatus = value;
break;
case 'tls':
this.tlsProtocol = value;
break;
// ... 其他需要解析的字段
}
});
} catch (error) {
this.errorMessage = 'Detection failed, please check network connection';
}
this.loading = false;
},
toggleDarkMode() {
this.darkMode = !this.darkMode;
this.applyDarkMode();
},
applyDarkMode() {
document.body.style.backgroundColor = this.darkMode ? '#212529' : '#fff';
document.body.style.color = this.darkMode ? 'white' : 'black';
},
flagUrl(countryCode) {
return `https://cdnjs.cloudflare.com/ajax/libs/flag-icon-css/3.5.0/flags/4x3/${countryCode.toLowerCase()}.svg`;
}
},
computed: {
cardStyle: function () {
return {
backgroundColor: this.darkMode ? '#343a40' : '#fff',
color: this.darkMode ? 'white' : 'black'
};
}
},
template: `
<div class="text-center">
<div class="mb-4 d-flex justify-content-between align-items-center">
<div>
<img src="./favicon.ico" alt="Cloudflare Logo" style="height: 50px;">
<span style="font-size: 1.5rem; vertical-align: middle; margin-left: 10px;">Cloudflare Center Detector</span>
</div>
<i :class="['fas', darkMode ? 'fa-sun' : 'fa-moon', 'fa-2x']" @click="toggleDarkMode" style="cursor: pointer;"></i>
</div>
<div class="card mx-auto" :style="cardStyle" style="max-width: 500px;">
<div class="card-body">
<div v-if="loading" class="spinner-grow text-primary" role="status">
<span class="sr-only">Loading...</span>
</div>
<div v-else-if="coloInfo" class="card-text">
<h5 class="mb-2">Data Centre Info:</h5>
<p><img :src="flagUrl(coloInfo.cca2)" alt="Flag" class="img-fluid mb-2" style="height: 20px;"> {{ coloInfo.region }} - {{ coloInfo.city }} ({{ coloInfo.cca2 }})</p>
<p v-if="ipAddress"><strong>IP Address:</strong> {{ ipAddress }}</p>
<p v-if="warpStatus"><strong>WARP Status:</strong> {{ warpStatus }}</p>
<p v-if="tlsProtocol"><strong>TLS Protocol:</strong> {{ tlsProtocol }}</p>
</div>
<p v-else>{{ errorMessage }}</p>
</div>
</div>
<!-- Google 地图 -->
<div v-if="coloInfo" class="card mx-auto mt-4" :style="cardStyle" style="max-width: 500px;">
<div class="card-body">
<h5 class="card-title mb-3">Data Centre Location</h5>
<iframe
width="100%"
height="250"
frameborder="0" style="border:0"
:src="'https://www.google.com/maps?q=' + coloInfo.lat + ',' + coloInfo.lon + '&z=8&output=embed'"
allowfullscreen>
</iframe>
</div>
</div>
<!-- 版权声明部分,本项目遵循GPLv3开源协议,未经允许禁止修改版权信息 -->
<div class="footer mt-5" style="color: gray; font-size: 0.8rem; display: flex; justify-content: center; align-items: center; gap: 15px;">
<!-- COPYRIGHT NOTICE -->
<p>Follows the <a href="https://www.gnu.org/licenses/gpl-3.0.html" target="_blank" style="color: inherit; text-decoration: none;"><i class="fas fa-code"></i> GNU General Public License v3.0</a></p>
<p><a href="https://github.com/WizisCool/Cloudflare-Center-Detector" target="_blank" style="color: inherit; text-decoration: none;"><i class="fab fa-github"></i> Cloudflare Center Detector</a></p>
<p><a href="https://dooo.ng" target="_blank" style="color: inherit; text-decoration: none;"><i class="fas fa-blog"></i> Dooo.ng</a></p>
</div>
<!-- End of Copyright Notice -->
</div>
`
});
new Vue({ el: '#app' });