-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
56 lines (48 loc) · 1.85 KB
/
main.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
54
55
56
// Initialize the console log2div first.
import { initLog2Div, toggleLog2DivVisibility } from './log2div.js';
(() => { initLog2Div(); })();
/**
* Show or hide the console.
*
* @param {KeyboardEvent} event The event to show/hide the console.
*/
async function showConsole(event) {
// CTRL-D shows the console.
if ((event.code == "KeyD") && (event.ctrlKey)) { toggleLog2DivVisibility(); }
}
/**
* Toggle the console.
*/
function toggleConsole() {
toggleLog2DivVisibility();
}
/**
* Log a message based on the log text input and log level.
*/
function logMessage() {
let text = document.getElementById('log')["value"];
let loglevel = document.getElementById("loglevel")["value"];
switch (loglevel) {
case "info": console.log(text); break;
case "warn": console.warn(text); break;
case "error": console.error(text); break;
}
}
(() => {
// Test console message.
console.log("This is %i %s", 1, "log message.");
console.log("This is %ca red message", "color: red;");
console.log("This is %ca %s message", "color: red;", "red");
console.log("This message is repeated");
console.log("This message is repeated");
console.log("This message is repeated");
console.log("This is %ca red message %cand this is blue", "color: red; font-size: 20px;", "color: blue; font-size: 15px;");
console.error("This message is repeated");
console.error("This message is repeated");
console.log("This is a long message with some Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec nec odio tempor. More lorem ispsum goes here if we need it to be here.");
window.addEventListener("keydown", showConsole, false);
let toggleButton = document.getElementById('toggleconsole');
toggleButton.addEventListener("click", toggleConsole);
let logButton = document.getElementById('logmessage');
logButton.addEventListener("click", logMessage);
})();