Created
April 27, 2016 11:31
-
-
Save dcollien/d3c276ecb4dd2eec565608e502de855a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <head> | |
| <script> | |
| var start_indicator = 'START'; | |
| var lineNum = 0; | |
| var render = function(newData) { | |
| var content = ''; | |
| newData = newData.replace(/^\s+|\s+$/g, ''); | |
| if (newData === '') return ''; | |
| var lines = newData.split('\\n'); | |
| lines.forEach(function(line, i) { | |
| if (line !== '' || i !== lines.length-1) { | |
| content += '<span id="line' + lineNum + '"></span>' + line + '<br>'; | |
| lineNum++; | |
| } | |
| }); | |
| return content; | |
| }; | |
| window.onload = function() { | |
| var bodyContent = document.body.innerHTML; | |
| document.body.style.background = '#222'; | |
| document.body.style.color = '#eee'; | |
| document.body.style.fontFamily = 'Monaco, monospace'; | |
| document.body.style.fontWeight = 'bold'; | |
| document.body.innerHTML = '<pre id="log-container">' + render(bodyContent) + '</pre>'; | |
| if (window.location.hash) { | |
| window.location.href = window.location.hash; | |
| } | |
| setInterval(function() { | |
| var isScrolled = false; | |
| var xhr = new XMLHttpRequest(); | |
| xhr.onreadystatechange = function() { | |
| if (xhr.readyState == 4 && xhr.status == 200) { | |
| var body = xhr.responseText.split('<!-- ' + start_indicator + ' -->')[1]; | |
| var newData = body.replace(bodyContent, ''); | |
| var newHTML = render(newData); | |
| if (newHTML) { | |
| if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) { | |
| isScrolled = true; | |
| } | |
| document.getElementById('log-container').innerHTML += newHTML; | |
| if (isScrolled) { | |
| window.scrollTo(0, document.body.scrollHeight); | |
| } | |
| } | |
| bodyContent = body; | |
| } | |
| }; | |
| xhr.open("GET", location.href, true); | |
| xhr.send(); | |
| }, 2500); | |
| }; | |
| </script> | |
| </head> | |
| <!-- START --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment