// ------ Jenkins ANSI color pure JS plugin https://github.com/jakubjosef/jenkins-ansi-color-js ------ //
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);
    }
});