-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathMMM-CountDown.js
executable file
·62 lines (51 loc) · 1.77 KB
/
MMM-CountDown.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
Module.register("MMM-CountDown",{
// Default module config.
defaults: {
event: "New Millenium:",
date: "3000-01-01",
showHours: true,
showMinutes: true,
showSeconds: true,
customInterval: 1000,
daysLabel: 'd',
hoursLabel: 'h',
minutesLabel: 'm',
secondsLabel: 's',
},
// set update interval
start: function() {
var self = this;
setInterval(function() {
self.updateDom(); // no speed defined, so it updates instantly.
}, this.config.customInterval);
},
// Update function
getDom: function() {
var wrapper = document.createElement("div");
var timeWrapper = document.createElement("div");
var textWrapper = document.createElement("div");
textWrapper.className = "align-left week dimmed medium";
timeWrapper.className = "time bright xlarge light";
textWrapper.innerHTML=this.config.event;
var today = new Date(Date.now());
var target = new Date(this.config.date);
var timeDiff = target - today;
// Set days, hours, minutes and seconds
var diffDays = Math.floor(timeDiff / (1000 * 60 * 60 * 24));
var diffHours = Math.floor((timeDiff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var diffMinutes = Math.floor((timeDiff % (1000 * 60 * 60)) / (1000 * 60));
var diffSeconds = Math.floor((timeDiff % (1000 * 60)) / 1000);
// Build the output
var hrs = '';
var mins = '';
var secs = '';
var days = diffDays + this.config.daysLabel;
if(this.config.showHours == true) hrs = diffHours + this.config.hoursLabel;
if(this.config.showMinutes == true) mins = diffMinutes + this.config.minutesLabel;
if(this.config.showSeconds == true) secs = diffSeconds + this.config.secondsLabel;
timeWrapper.innerHTML = days + hrs + mins + secs;
wrapper.appendChild(textWrapper);
wrapper.appendChild(timeWrapper);
return wrapper;
}
});