Jakub Josef | 52c3f12 | 2017-08-09 13:14:07 +0200 | [diff] [blame^] | 1 | function DOMReady(fn) { |
| 2 | if (document.attachEvent ? document.readyState === "complete" : document.readyState !== "loading"){ |
| 3 | fn(); |
| 4 | } else { |
| 5 | document.addEventListener('DOMContentLoaded', fn); |
| 6 | } |
| 7 | } |
| 8 | function addScript(src, callback, async) { |
| 9 | var s = document.createElement('script'); |
| 10 | s.setAttribute('src', src); |
| 11 | s.onload=callback; |
| 12 | if(async) s.async = true |
| 13 | document.body.appendChild(s); |
| 14 | } |
| 15 | |
| 16 | DOMReady(function(){ |
| 17 | // init ansi colors |
| 18 | addScript("/userContent/theme/js/ansi_up.js", (function(contentSelector){ |
| 19 | var ansiUp = new AnsiUp |
| 20 | , $console = document.querySelector(contentSelector) |
| 21 | , entities = { |
| 22 | 'amp': '&', |
| 23 | 'apos': '\'', |
| 24 | '#x27': '\'', |
| 25 | '#x2F': '/', |
| 26 | '#39': '\'', |
| 27 | '#47': '/', |
| 28 | 'lt': '<', |
| 29 | 'gt': '>', |
| 30 | 'nbsp': ' ', |
| 31 | 'quot': '"' |
| 32 | } |
| 33 | , decodeHTMLEntities = function (text) { |
| 34 | return text.replace(/&([^;]+);/gm, function (match, entity) { |
| 35 | return entities[entity] || match |
| 36 | }) |
| 37 | } |
| 38 | , colorizeFn = function(){ |
| 39 | $console.innerHTML = decodeHTMLEntities(ansiUp.ansi_to_html($console.innerHTML)); |
| 40 | }; |
| 41 | |
| 42 | colorizeFn(); |
| 43 | $console.addEventListener('change', colorizeFn, false); |
| 44 | }).bind(null,".console-output"), true); |
| 45 | }); |