-
Notifications
You must be signed in to change notification settings - Fork 8
/
regression-script.js
38 lines (34 loc) · 1.38 KB
/
regression-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
import { format } from "https://esm.sh/v135/[email protected]/format.mjs"
import { formatDistanceToNow } from "https://esm.sh/v135/[email protected]/formatDistanceToNow.mjs"
import { addSeconds } from "https://esm.sh/v135/[email protected]/addSeconds.mjs"
const dateFormat = "MMM dd HH:mm:ss"
const optionsAgo = {addSuffix: true}
const duration = pt => addSeconds(new Date(), parseInt(pt.slice(2, -1)))
function localiseTimes(all) {
for (const elt of Array.from(document.getElementsByTagName('time'))) {
if (elt.classList.contains('ago')) {
elt.title = elt.innerText.slice(elt.innerText.indexOf('[')+1,-1)
elt.innerText = ` [${formatDistanceToNow(elt.dateTime, optionsAgo)}]`
}
else if (elt.classList.contains('since')) {
elt.title = elt.innerText
elt.innerText = `[elapsed: ${formatDistanceToNow(elt.dateTime)}]`
}
else if (elt.classList.contains('duration')) {
elt.title = elt.innerText
elt.innerText = `[average: ${formatDistanceToNow(duration(elt.dateTime))}]`
}
else if (all) {
elt.title = elt.innerText
elt.innerText = format(elt.dateTime, dateFormat)
}
}
}
const upds = new EventSource('/regression-updates.cgi')
upds.onmessage = function(e) {
if (location.pathname.includes('/job/' + e.data) ||
!(location.pathname.includes('/job/')))
location.reload()
}
localiseTimes(true)
setInterval(localiseTimes, 60000, false)