Skip to content

Commit 9c0661a

Browse files
committed
feat(list.html): add webpage
- Follow the prettier, stylelint-config-standard and stylelint-config-recess-order rules
1 parent 45bf1d3 commit 9c0661a

File tree

1 file changed

+145
-0
lines changed

1 file changed

+145
-0
lines changed

list.html

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<link
7+
rel="icon"
8+
href="https://build.archlinuxcn.org/favicon.ico"
9+
type="image/ico"
10+
/>
11+
<title>Arch Linux CN Community Repository Mirrors</title>
12+
<meta
13+
name="description"
14+
content="Here is a list of public mirrors of Arch Linux CN Community Repository"
15+
/>
16+
<style>
17+
.table-container {
18+
box-sizing: border-box;
19+
width: 100%;
20+
margin: auto;
21+
overflow: auto;
22+
}
23+
24+
table {
25+
border-collapse: collapse;
26+
}
27+
28+
th {
29+
padding: 15px 30px;
30+
color: hsl(200deg 92% 41%);
31+
text-align: left;
32+
border-bottom: 2px solid hsl(0deg 0% 87%);
33+
}
34+
35+
td {
36+
padding: 15px 30px;
37+
color: hsl(212deg 19% 27%);
38+
text-align: left;
39+
white-space: nowrap;
40+
}
41+
42+
a {
43+
color: hsl(200deg 92% 41%);
44+
text-decoration: none;
45+
}
46+
47+
tr:hover td {
48+
background-color: hsl(199deg 82% 93%);
49+
}
50+
51+
#search {
52+
box-sizing: border-box;
53+
width: 100%;
54+
padding: 10px;
55+
margin: 100px auto 20px;
56+
border: 1px solid hsl(0deg 0% 89%);
57+
}
58+
</style>
59+
</head>
60+
61+
<body>
62+
<input
63+
id="search"
64+
type="text"
65+
oninput="filterTable()"
66+
placeholder="Search"
67+
/>
68+
<div class="table-container">
69+
<table id="table">
70+
<thead>
71+
<tr>
72+
<th>Provider</th>
73+
<th>Region</th>
74+
<th>Protocols</th>
75+
<th>lastupdate</th>
76+
<th>x86_64</th>
77+
<th>any</th>
78+
</tr>
79+
</thead>
80+
<tbody id="tbody"></tbody>
81+
</table>
82+
</div>
83+
<script>
84+
const table = document.getElementById("table");
85+
const tbody = document.getElementById("tbody");
86+
87+
const loadData = async function () {
88+
const res = await fetch("https://archlinuxcn.org/mirrors/stats.json");
89+
const data = await res.json();
90+
91+
const archlinuxcn = data.archlinuxcn;
92+
archlinuxcn.sort((a, b) => {
93+
const toSeconds = (time) => {
94+
let days = 0;
95+
if (time.includes("day")) {
96+
const parts = time.split(", ");
97+
days = parseInt(parts[0], 10);
98+
time = parts[1];
99+
}
100+
const parts = time.split(":").map((part) => parseInt(part, 10));
101+
const seconds =
102+
days * 86400 + parts[0] * 3600 + parts[1] * 60 + parts[2];
103+
return seconds;
104+
};
105+
if (a.tag === "success" && b.tag === "success") {
106+
const lastupdateA = toSeconds(a.information.lastupdate);
107+
const lastupdateB = toSeconds(b.information.lastupdate);
108+
return Math.sign(lastupdateA - lastupdateB);
109+
}
110+
});
111+
112+
const createRow = (item) => `
113+
<tr>
114+
<td>
115+
<a href="${item.url}">${item.provider}</a>
116+
${item.comment ? `<br><div>${item.comment}</div>` : ""}
117+
</td>
118+
<td>${item.region}</td>
119+
<td>${item.protocols.join(", ")}</td>
120+
<td>${item.information.lastupdate}</td>
121+
<td>${item.information["x86_64/archlinuxcn.db"]}</td>
122+
<td>${item.information["any/archlinuxcn.db"]}</td>
123+
</tr>
124+
`;
125+
const rows = archlinuxcn.map(createRow).join("");
126+
tbody.innerHTML = rows;
127+
};
128+
loadData();
129+
130+
function filterTable() {
131+
const input = document.getElementById("search");
132+
const filter = input.value.toUpperCase();
133+
const table = document.getElementById("table");
134+
const trs = Array.from(table.getElementsByTagName("tr")).slice(1);
135+
trs.forEach((tr) => {
136+
const tds = Array.from(tr.getElementsByTagName("td")).map(
137+
(td) => td && td.textContent.toUpperCase()
138+
);
139+
const found = tds.some((content) => content.includes(filter));
140+
tr.style.display = found ? "" : "none";
141+
});
142+
}
143+
</script>
144+
</body>
145+
</html>

0 commit comments

Comments
 (0)