Compare commits

...

5 Commits

2 changed files with 39 additions and 26 deletions

View File

@ -1,5 +1,3 @@
window.console = {};
window.onload = function () {
var output = document.getElementById("output");
var input = document.getElementById("input");
@ -51,7 +49,6 @@ window.onload = function () {
// TODO: Cool object output and errors with stack traces?
function tryString (value) {
try {
if (value instanceof Error && value.message) return removeCarriageReturns(value.message);
return removeCarriageReturns(new String(value).toString());
} catch (err) {
// Give up, just print the type.
@ -59,8 +56,12 @@ window.onload = function () {
}
}
function makeLogger (color) {
var originalConsole = window.console;
window.console = {};
function makeLogger (name, color) {
return function () {
if (originalConsole && originalConsole[name] && originalConsole[name].apply) originalConsole[name].apply(originalConsole, arguments);
var entry = document.createElement('div');
entry.style.margin = '0';
entry.style.padding = '1px';
@ -76,11 +77,11 @@ window.onload = function () {
}
}
console.log = makeLogger();
console.debug = makeLogger('darkgray');
console.info = makeLogger();
console.warn = makeLogger('orange');
console.error = makeLogger('red');
console.log = makeLogger('log');
console.debug = makeLogger('debug', 'darkgray');
console.info = makeLogger('info');
console.warn = makeLogger('warn', 'orange');
console.error = makeLogger('error', 'red');
console.assert = function (assertion) {
if (assertion) return;
@ -103,43 +104,43 @@ window.onload = function () {
stack += '\n ';
current = current.caller;
}
console.log(stack.trim())
console.log(stack.trim());
}
var inputLogger = makeLogger('lightBlue');
var inputLogger = makeLogger('log', 'lightblue');
function run () {
var selected = getSelectedText(input);
var code = selected ? selected : input.value;
var code = getSelectedText(input) || input.value;
if (!code.trim()) return;
inputLogger(code);
try {
console.log(tryString(eval(code)));
console.log(eval(code));
} catch (err) {
console.error(err);
}
}
console.clear = function () {
if (originalConsole && originalConsole.clear) {
if (originalConsole.clear.apply) originalConsole.clear.apply(originalConsole, arguments);
else originalConsole.clear();
}
output.innerHTML = "";
}
input.onkeypress = function (event) {
if (!event) event = window.event;
// Run code if Shift+Enter is pressed
if (event && event.keyCode === 13 && event.shiftKey) {
event.preventDefault();
event.cancelBubble = true;
event.returnValue = false;
if (event.stopPropagation) event.stopPropagation();
if (event.preventDefault) event.preventDefault();
run();
}
}
runButton.onclick = run;
clearButton.onclick = console.clear;
// Try to detect the wizard extensions.
if (typeof window.external === 'object' && typeof window.external.SetWizardButtons === 'unknown') {
window.external.SetHeaderText('JavaScript Console', "Explore this wizard's JavaScript environment.");
// Enable the back button
window.external.SetWizardButtons(1, 0, 0);
}
if (/MSIE 7.0/.test(navigator.userAgent)) {
/*
* For some reason, IE 7 messes up the textarea's width and height
@ -153,7 +154,18 @@ window.onload = function () {
}
}
// An onback function is required by the web wizard specification
window.onback = function () {
window.external.FinalBack();
}
// Try to detect the wizard extensions.
if (typeof window.external === 'object') {
if (typeof window.external.SetHeaderText === 'unknown')
window.external.SetHeaderText('JavaScript Console', "Explore this wizard's JavaScript environment.");
if (typeof window.external.SetWizardButtons === 'unknown')
window.external.SetWizardButtons(1, 0, 0);
if (typeof window.external.FinalBack === 'unknown') {
// An onback function is required by the web wizard specification
window.onback = function () {
window.external.FinalBack();
}
}
}

View File

@ -3,6 +3,7 @@
<head>
<title>JavaScript Console</title>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<link rel="stylesheet" type="text/css" href="console.css" />
<link rel="icon" type="image/x-icon" href="jsconsole.ico" />
<link rel="shortcut icon" type="image/x-icon" href="jsconsole.ico" />