-
Notifications
You must be signed in to change notification settings - Fork 6
/
jenkins-ansi-color.js
56 lines (53 loc) · 1.9 KB
/
jenkins-ansi-color.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
function DOMReady(fn) {
if (document.attachEvent ? document.readyState === "complete" : document.readyState !== "loading") {
fn();
} else {
document.addEventListener('DOMContentLoaded', fn);
}
}
function addScript(src, callback, async) {
var s = document.createElement('script');
s.setAttribute('src', src);
s.onload = callback;
if (async) s.async = true
document.body.appendChild(s);
}
DOMReady(function() {
var consoleOutputSelector = ".console-output";
if (document.querySelector(consoleOutputSelector)) {
// init ansi colors
addScript("/userContent/theme/js/ansi_up.js", function() {
var ansiUp = new AnsiUp,
$console = document.querySelector(consoleOutputSelector),
entities = {
'amp': '&',
'apos': '\'',
'#x27': '\'',
'#x2F': '/',
'#39': '\'',
'#47': '/',
'lt': '<',
'gt': '>',
'nbsp': ' ',
'quot': '"'
},
decodeHTMLEntities = function(text) {
return text.replace(/&([^;]+);/gm, function(match, entity) {
return entities[entity] || match
})
},
colorizeFn = function() {
$console.innerHTML = decodeHTMLEntities(ansiUp.ansi_to_html($console.innerHTML));
};
colorizeFn();
// create prototype.js global ajax handle responder
Ajax.Responders.register({
onComplete: function(req, res) {
if (req.body.indexOf("start=") != -1 && res.status==200 && res.responseText != "") {
colorizeFn();
}
}
});
}, true);
}
});