forked from SukkaLab/cfdc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.html
executable file
·220 lines (190 loc) · 8.87 KB
/
data.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="shortcut icon" type="image/ico" href="https://cdn.jsdelivr.net/npm/[email protected]">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no,minimal-ui">
<title>Cloudflare Data Center - Sukka's Lab</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]">
<link rel="preload" as="fetch" crossorigin href="https://lab.skk.moe/cfdc/cfdc.json">
<link rel="preload" as="fetch" crossorigin href="https://www.cloudflarestatus.com/index.html">
<link rel="preload" as="fetch" crossorigin href="https://cors-anywhere.herokuapp.com/https://www.cloudflare.com/data/current-pops.csv">
</head>
<body>
<div class="container">
<section class="section sk-text-center">
<h1 class="title">Cloudflare Data Center</h1>
<p id="cfdc-num"></p>
<br>
<p id="cfdc-cf"></p>
<p id="cf-cfdc"></p>
<p></p>
</section>
</div>
<script>
const csv2array = (strData, strDelimiter) => {
// ref: http://stackoverflow.com/a/1293163/2343
// This will parse a delimited string into an array of
// arrays. The default delimiter is the comma, but this
// can be overriden in the second argument.
// Check to see if the delimiter is defined. If not,
// then default to comma.
strDelimiter = (strDelimiter || ",");
// Create a regular expression to parse the CSV values.
let objPattern = new RegExp(
(
// Delimiters.
"(\\" + strDelimiter + "|\\r?\\n|\\r|^)" +
// Quoted fields.
"(?:\"([^\"]*(?:\"\"[^\"]*)*)\"|" +
// Standard fields.
"([^\"\\" + strDelimiter + "\\r\\n]*))"
),
"gi"
);
// Create an array to hold our data. Give the array
// a default empty first row.
let arrData = [[]];
// Create an array to hold our individual pattern
// matching groups.
let arrMatches = null;
// Keep looping over the regular expression matches
// until we can no longer find a match.
while (arrMatches = objPattern.exec(strData)) {
// Get the delimiter that was found.
let strMatchedDelimiter = arrMatches[1];
// Check to see if the given delimiter has a length
// (is not the start of string) and if it matches
// field delimiter. If id does not, then we know
// that this delimiter is a row delimiter.
if (
strMatchedDelimiter.length &&
strMatchedDelimiter !== strDelimiter
) {
// Since we have reached a new row of data,
// add an empty row to our data array.
arrData.push([]);
}
let strMatchedValue;
// Now that we have our delimiter out of the way,
// let's check to see which kind of value we
// captured (quoted or unquoted).
if (arrMatches[2]) {
// We found a quoted value. When we capture
// this value, unescape any double quotes.
strMatchedValue = arrMatches[2].replace(
new RegExp("\"\"", "g"),
"\""
);
} else {
// We found a non-quoted value.
strMatchedValue = arrMatches[3];
}
// Now that we have our value string, let's add
// it to the data array.
arrData[arrData.length - 1].push(strMatchedValue);
}
// Return the parsed data.
return (arrData);
}
const arrayItemDel = (array, value) => {
let index = array.indexOf(value);
if (index > -1) {
array.splice(index, 1);
}
}
const _getJson = (url) =>
fetch(url, {
method: 'GET'
}).then(resp => Promise.all([resp.ok, resp.status, resp.json(), resp.headers])
).then(([ok, status, json, headers]) => {
if (ok) {
let data = {
ok,
status,
data: json,
headers
}
return data;
} else {
throw new Error(JSON.stringify(json.error));
}
}).catch(error => {
throw error;
}),
_getTxt = (url) =>
fetch(url, {
method: 'GET'
}).then(resp => Promise.all([resp.ok, resp.status, resp.text(), resp.headers])
).then(([ok, status, json, headers]) => {
if (ok) {
let data = {
ok,
status,
data: json,
headers
}
return data;
} else {
throw new Error(JSON.stringify(json.error));
}
}).catch(error => {
throw error;
});
let CFDC = {
data: [],
cfdata: [],
compare: () => {
_getJson('cfdc.json')
.then(resp => {
for (let i in resp.data) {
CFDC.data.push(i);
}
}).then(() => {
_getTxt('https://www.cloudflarestatus.com/index.html')
.then(resp => {
let container = document.createElement('div');
//container.setAttribute('style', 'display: none');
container.innerHTML = resp.data;
let $itemList = container.querySelectorAll('.component-inner-container .name');
let List = [];
for (let i of $itemList) {
if (/.*?-.*?\((.*?)\)/g.test(i.innerHTML)) {
List.push(/.*?-.*?\((.*?)\)/g.exec(i.innerHTML)['1'].trim());
}
}
CFDC.cfdata = List;
}).then(() => {
_getTxt('https://cors-anywhere.herokuapp.com/https://www.cloudflare.com/data/current-pops.csv')
.then((resp) => {
document.getElementById('cfdc-num').innerHTML = `<strong>cfdc.json:</strong> ${CFDC.data.length} | <strong>Cloudflare Statuspage:</strong> ${CFDC.cfdata.length} | <strong>Cloudflare Network Map:</strong> ${csv2array(resp.data).length}`;
})
let data = JSON.parse(JSON.stringify(CFDC.data))
let cfdata = JSON.parse(JSON.stringify(CFDC.cfdata));
for (let i in CFDC.data) {
for (let j in CFDC.cfdata) {
if (CFDC.data[i] === CFDC.cfdata[j]) {
arrayItemDel(cfdata, CFDC.cfdata[j]);
break;
}
}
}
for (let k in CFDC.cfdata) {
for (let l in CFDC.data) {
if (CFDC.cfdata[k] === CFDC.data[l]) {
arrayItemDel(data, CFDC.data[l]);
break;
}
}
}
document.getElementById('cfdc-cf').innerHTML = `<strong>cfdc.json has those datacenters that cloudflare statuspages don't have:</strong><br>${data}`;
document.getElementById('cf-cfdc').innerHTML = `<strong>cloudflare statuspages has those datacenters that cfdc.json don't have:</strong><br>${cfdata}`;
})
})
}
}
CFDC.compare();
</script>
</body>
</html>