-
Notifications
You must be signed in to change notification settings - Fork 0
/
console.js
53 lines (46 loc) · 1.14 KB
/
console.js
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Init DOM
const consoleContainer = document.createElement("div");
consoleContainer.classList.add("console");
const legend = document.createElement("small");
legend.textContent = "Console";
consoleContainer.append(legend);
const vConsole = document.createElement("pre");
consoleContainer.append(vConsole);
window.addEventListener('DOMContentLoaded', (event) => {
document.body.append(consoleContainer);
});
// Style
const style = document.createElement("style");
style.textContent = `.console {
margin: 2em 0;
}
.console small {
text-transform: uppercase;
color: silver;
}
pre {
border: solid 1px Silver;
height: 30vh;
overflow-y: scroll;
margin: 0 0;
font-size: .85em;
resize:both;
}`;
document.head.append(style)
const originalConsole = console.log;
// Overwrite console.log
console.log = (...a) => {
a.map((l) => {
let t;
if (typeof l.toString == "function") {
l = l.toString();
} else {
l = JSON.stringify(l);
}
t = document.createTextNode(`${l} `);
vConsole.appendChild(t);
});
vConsole.appendChild(document.createTextNode("\n"));
vConsole.scrollTop = vConsole.scrollHeight;
originalConsole(...a);
}