forked from OSWeekends/coolsola
-
Notifications
You must be signed in to change notification settings - Fork 0
/
coolsola.js
79 lines (52 loc) · 1.8 KB
/
coolsola.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
var coolsola = {};
// Config
coolsola.setup = {
mute: false,
HTMLMode: false,
style: {
log: 'background: #FF00FF; color: #FFF; font-size:12px;',
warn: 'background: yellow; color: #333; font-size:12px;',
error: 'background: #E60000; color: #FFF; font-size:12px;',
assert: 'background: #FABADA; color: #FFF; font-size:12px;'
}
};
coolsola.resources = {
messages: []
}
coolsola.logger = function(){
var element = document.getElementById("coolsola")
if(element){
var htmlContent = ""
coolsola.resources.messages.forEach(function(item){
htmlContent += "<p>"+item+"</p>"
})
element.innerHTML = htmlContent;
}
}
// Métodos
coolsola.msg = function(data, type){
data = new Date().getTime() + " | " + data.trim();
// Almacenar el dato
coolsola.resources.messages.push(data)
// Mostrar al usuario
if(!coolsola.setup.mute){
var paleta = ["log", "warn", "error", "assert"];
if(type && paleta.indexOf(type) !== -1){
console.log('%c ' + data, coolsola.setup.style[type]);
} else {
console.log(data);
}
}
// Actualizar logger
if(coolsola.setup.HTMLMode){
coolsola.logger()
}
}
coolsola.msg("Coolsola - v.0.2.0: Cargado....", "warn");
document.addEventListener("DOMContentLoaded", function(event) {
if(coolsola.setup.HTMLMode){
document.body.innerHTML += "<h3>Coolsola Logger!</h3><div id='coolsola'></div>"
console.log(document.body)
coolsola.msg("Coolsola - v.0.2.0: Cargado en HTML....");
}
});