Skip to content

Commit 01e8ec1

Browse files
authored
Add certManager.js to fetch and render certificates
1 parent 08650f9 commit 01e8ec1

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

web/certManager.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
const README_URL =
2+
"https://raw.githubusercontent.com/ProStore-iOS/certificates/refs/heads/main/README.md";
3+
4+
fetch(README_URL)
5+
.then(res => res.text())
6+
.then(md => {
7+
renderRecommended(md);
8+
renderTable(md);
9+
renderUpdates(md);
10+
});
11+
12+
function renderRecommended(md) {
13+
const match = md.match(/# Recommend Certificate\s+\*\*(.+?)\*\*/);
14+
if (!match) return;
15+
16+
document.getElementById("recommended").innerHTML = `
17+
<h2>⭐ Recommended Certificate</h2>
18+
<p>${match[1]}</p>
19+
`;
20+
}
21+
22+
function renderTable(md) {
23+
const tableMatch = md.match(/\| Company \|[\s\S]*?\n\n/);
24+
if (!tableMatch) return;
25+
26+
const lines = tableMatch[0].trim().split("\n").slice(2);
27+
let rows = "";
28+
29+
lines.forEach(line => {
30+
const cols = line.split("|").map(c => c.trim()).filter(Boolean);
31+
if (cols.length < 6) return;
32+
33+
rows += `
34+
<tr>
35+
<td>${cols[0]}</td>
36+
<td>${cols[1]}</td>
37+
<td class="status revoked">❌ Revoked</td>
38+
<td>${cols[3]}</td>
39+
<td>${cols[4]}</td>
40+
<td>${cols[5]}</td>
41+
</tr>
42+
`;
43+
});
44+
45+
document.getElementById("certTable").innerHTML = `
46+
<table class="cert-table">
47+
<thead>
48+
<tr>
49+
<th>Company</th>
50+
<th>Type</th>
51+
<th>Status</th>
52+
<th>Valid From</th>
53+
<th>Valid To</th>
54+
<th>Download</th>
55+
</tr>
56+
</thead>
57+
<tbody>${rows}</tbody>
58+
</table>
59+
`;
60+
}
61+
62+
function renderUpdates(md) {
63+
const section = md.split("# Updates")[1];
64+
if (!section) return;
65+
66+
const lines = section.split("\n").filter(l => l.startsWith("**"));
67+
68+
document.getElementById("updates").innerHTML = `
69+
<h2>📰 Updates</h2>
70+
${lines.map(l => `<div class="update-item">${l}</div>`).join("")}
71+
`;
72+
}

0 commit comments

Comments
 (0)