tangled
alpha
login
or
join now
madoka.systems
/
labyrinth
0
fork
atom
this repo has no description
madoka.systmes
0
fork
atom
overview
issues
pulls
pipelines
cache status and lint
madoka.systems
1 month ago
bb912f57
085dd118
1/1
deploy.yaml
success
57s
+38
-36
1 changed file
expand all
collapse all
unified
split
static
js
status.js
+38
-36
static/js/status.js
···
1
1
-
(function() {
2
2
-
const BADGE_URL = 'https://status.madoka.systems/api/badge/12/status';
3
3
-
const REFRESH_INTERVAL = 60000; // 1 minute
1
1
+
/* global localStorage */
2
2
+
(function () {
3
3
+
'use strict'
4
4
5
5
-
async function fetchStatus() {
6
6
-
try {
7
7
-
const response = await fetch(BADGE_URL);
8
8
-
if (!response.ok) throw new Error('badge request failed');
5
5
+
const BADGE_URL = 'https://status.madoka.systems/api/badge/12/status'
6
6
+
const REFRESH_INTERVAL = 60000
7
7
+
const CACHE_KEY = 'site-status'
8
8
+
const STATUS_CLASSES = ['up', 'down', 'pending', 'maintenance', 'unknown']
9
9
10
10
-
const svg = await response.text();
10
10
+
function parseStatus (svg) {
11
11
+
const lower = svg.toLowerCase()
12
12
+
if (lower.includes('>up<') || lower.includes('up</text>')) return 'up'
13
13
+
if (lower.includes('>down<') || lower.includes('down</text>')) return 'down'
14
14
+
if (lower.includes('>pending<') || lower.includes('pending</text>')) return 'pending'
15
15
+
if (lower.includes('>maintenance<') || lower.includes('maintenance</text>')) return 'maintenance'
16
16
+
return 'unknown'
17
17
+
}
11
18
12
12
-
// parse status from badge svg text content
13
13
-
if (svg.includes('>Up<') || svg.includes('up</text>')) {
14
14
-
updateIndicator('up');
15
15
-
} else if (svg.includes('>Down<') || svg.includes('down</text>')) {
16
16
-
updateIndicator('down');
17
17
-
} else if (svg.includes('>Pending<') || svg.includes('pending</text>')) {
18
18
-
updateIndicator('pending');
19
19
-
} else if (svg.includes('>Maintenance<') || svg.includes('maintenance</text>')) {
20
20
-
updateIndicator('maintenance');
21
21
-
} else {
22
22
-
updateIndicator('unknown');
23
23
-
}
19
19
+
function updateIndicator (status) {
20
20
+
const indicator = document.getElementById('status-indicator')
21
21
+
if (!indicator) return
24
22
25
25
-
} catch (error) {
26
26
-
console.error('failed to fetch uptime status:', error);
27
27
-
updateIndicator('unknown');
28
28
-
}
23
23
+
indicator.classList.remove(...STATUS_CLASSES)
24
24
+
indicator.classList.add(status)
29
25
}
30
26
31
31
-
function updateIndicator(status) {
32
32
-
const indicator = document.getElementById('status-indicator');
33
33
-
if (!indicator) return;
27
27
+
async function fetchStatus () {
28
28
+
try {
29
29
+
const response = await fetch(BADGE_URL)
30
30
+
if (!response.ok) throw new Error('badge request failed')
31
31
+
32
32
+
const svg = await response.text()
33
33
+
const status = parseStatus(svg)
34
34
35
35
-
// remove all status classes
36
36
-
indicator.classList.remove('up', 'down', 'pending', 'maintenance', 'unknown');
37
37
-
// add current status class
38
38
-
indicator.classList.add(status);
35
35
+
updateIndicator(status)
36
36
+
localStorage.setItem(CACHE_KEY, status)
37
37
+
} catch (error) {
38
38
+
console.error('failed to fetch uptime status:', error)
39
39
+
updateIndicator('unknown')
40
40
+
}
39
41
}
40
42
41
41
-
// fetch immediately on load
42
42
-
fetchStatus();
43
43
+
const cached = localStorage.getItem(CACHE_KEY)
44
44
+
if (cached) updateIndicator(cached)
43
45
44
44
-
// refresh periodically
45
45
-
setInterval(fetchStatus, REFRESH_INTERVAL);
46
46
-
})();
46
46
+
fetchStatus()
47
47
+
setInterval(fetchStatus, REFRESH_INTERVAL)
48
48
+
})()