forked from jasonrclark/fedwiki-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
color.html
47 lines (43 loc) · 1.41 KB
/
color.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
<pre id=report style="white-space: pre-wrap;">working</pre>
<script type=module>
import * as frame from 'http://code.fed.wiki/assets/v1/frame.js'
const ansi = {
'30': 'BLACK',
'31': 'RED',
'32': 'GREEN',
'33': 'LIMEGREEN',
'34': 'BLUE',
'35': 'PURPLE',
'36': 'DARKCYAN',
'37': 'WHITE'
}
const url = 'http://ward.dojo.fed.wiki/assets/pages/federation-browser-in-java/output.txt'
const text = await fetch(url).then(res => res.text())
window.doopen = event =>
window.parent.postMessage({
action:"doInternalLink",
title: event.target.textContent,
site: event.target.dataset.site,
keepLineup: event.shiftKey
}, "*")
let tail = ''
window.report.innerHTML = text.split(/\n/)
.map(line => {
const summary = line.match(/ << \d+ case (.*?) >>/)
if(summary) {
const head = `${tail}<details><summary>${summary[1]}</summary>`
tail = `</details>`
return head
}
const head = line.match(/^(.*?)\u001b\[32m (.*?)\u001b\[0m/)
if (head) {
return `<img width=10 src="http://${head[2]}/favicon.png"> <span data-site=${head[2]} onclick=doopen(event)>${head[1]}</span>\n`
}
return line
.replace(/&/g,'&')
.replace(/</g,'<')
.replace(/\u001b\[(.*?)m/ig, (_,n) => n!='0' ? `<font color=${ansi[n]}>` : `</font>`)
.replace(/$/,"\n")
})
.join("")+tail
</script>