-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsoleOutput.js
More file actions
37 lines (30 loc) · 973 Bytes
/
consoleOutput.js
File metadata and controls
37 lines (30 loc) · 973 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
var consoleOutput = [];
var originalConsoleLog = console.log;
console.log = function() {
var message = Array.from(arguments).map(convertToString).join(" ");
consoleOutput.push('<span class="log">' + message + '</span>');
originalConsoleLog.apply(console, arguments);
updateConsoleOutput();
};
console.error = function() {
var message = Array.from(arguments).map(convertToString).join(" ");
consoleOutput.push('<span class="error">' + message + '</span>');
originalConsoleLog.apply(console, arguments);
updateConsoleOutput();
};
function updateConsoleOutput() {
var consoleDiv = document.getElementById("output");
consoleDiv.innerHTML = consoleOutput.join(" ");
}
function convertToString(value) {
if (typeof value === "string") {
return value;
} else if (typeof value === "object" && value !== null) {
return JSON.stringify(value);
} else {
return String(value);
}
}
window.onload = function() {
consoleOutput.splice(0);
};