Last active
August 29, 2015 14:05
-
-
Save kolodny/591de7c4fdfd33ab7a51 to your computer and use it in GitHub Desktop.
This file contains 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
var logged; | |
var logPre; | |
var returned; | |
var $0; | |
var p = prompt('Enter expression to evaluate'); | |
do { | |
try { | |
logged = []; | |
returned = $0 = eval(p); | |
try { | |
if ([RegExp, Function].indexOf(returned.constructor) > -1) { | |
returned = 'Returned (' + returned.constructor.toString().match(/[A-Z]\w+/)[0] + '):\n' + returned; | |
} else { | |
returned = 'Returned:\n' + JSON.stringify($0, null, ' '); | |
} | |
} catch (f) {} | |
} catch (e) { | |
returned = 'Errored: ' + e.message; | |
} | |
} while (p && (p = prompt( | |
(logged.length ? 'logged:\n' + logged.join('\n') + '\n' : '') + | |
returned | |
, p))); | |
setTimeout(function() { | |
document.body.removeChild(logPre) | |
}, 10000); | |
function log(arg) { | |
try { arg = JSON.stringify(arg, null, ' '); } catch (e) {} | |
if (!logPre) { | |
logPre = document.createElement('pre'); | |
logPre.style.position = 'fixed'; | |
logPre.style.top = logPre.style.left = '10px'; | |
logPre.style.zIndex = 999; | |
logPre.style.background = 'wheat'; | |
logPre.style.padding = '5px'; | |
document.body.appendChild(logPre); | |
} | |
logPre.innerText = arg; | |
logged.push(arg); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment