-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMMM-YoureBeautiful.js
125 lines (108 loc) · 4.11 KB
/
MMM-YoureBeautiful.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/* global Module */
Module.register("MMM-YoureBeautiful", {
defaults: {
faceFile: "jamesblunt.mp4",//set as list of videos
faceFileText: "jamesblunt.mpg",
halloweenFaceFile: "scary.mp4",
halloweenFaceFileText: "scary.mpg",
birthdayFaceFile: "happyBirthday.mpg",
birthdayFaceFileText: "happyBirthday.mpg",
birthday: {year: 1977, month: 3, day: 6},
likelyHood: {numerator: 1, denominator: 100}, //1 chance in 100
interval: 2 * 60 * 1000 //2mins
},
start: function () {
if (this.config.likelyHood.numerator > this.config.likelyHood.denominator) {
this.config.likelyHood.numerator = this.config.likelyHood.denominator;
}
},
getGetOrdinalHelper: function (n) {
var s = ["th", "st", "nd", "rd"],
v = n % 100;
return n + (s[(v - 20) % 10] || s[v] || s[0]);
},
getDom: function () {
var self = this;
var message = this.config.faceFileText;
var video = this.config.faceFile;
var now = new Date();
var year = now.getFullYear();
var month = (now.getMonth() + 1);
var day = now.getDate();
var daytypes = ["normal", "birthday", "halloween"];
var daytype = daytypes[0];
if ((month === this.config.birthday.month) && (day === this.config.birthday.day)) {
daytype = daytypes[1];
}
if ((month === 10) && (day === 31)) {
daytype = daytypes[2];
}
if (((month === 10) && (day === 31)) && ((month === this.config.birthday.month) && (day === this.config.birthday.day))) {
daytype = daytypes[Math.ceil(Math.random() * 2)];
}
if (daytype === daytypes[1]) {
video = this.config.birthdayFaceFile;
if (this.config.birthdayFaceFileText !== undefined) {
message = this.config.birthdayFaceFileText;
} else {
message = "Happy " + this.getGetOrdinalHelper(year - this.config.birthday.year) + " Birthday";
}
}
if (daytype === daytypes[2]) {
video = this.config.halloweenFaceFile;
message = this.config.halloweenFaceFileText;
}
var wrapper = document.createElement("div");
wrapper.classList.add("black_overlay");
var container = document.createElement("div");
container.classList.add("content");
var videoDiv = document.createElement("video");
videoDiv.src = "/modules/" + self.name + "/public/" + video;
videoDiv.id = "MMM-YoureBeautifulVideoDiv";
videoDiv.autoplay = false;
container.appendChild(videoDiv);
var title = document.createElement("div");
title.classList.add("bold", "large", "message");
title.innerHTML = message;
container.appendChild(title);
wrapper.appendChild(container);
var i = setInterval(function () {
if (videoDiv.readyState > 0) {
self.duration = videoDiv.duration;
clearInterval(i);
}
}, 200);
return wrapper;
},
getStyles: function () {
return [this.file("css/MMM-YoureBeautiful.css")];
},
showVid: function () {
var self = this;
var video = document.getElementById("MMM-YoureBeautifulVideoDiv");
if (video.readyState === 0) {
this.hide();
return;
}
var rolledDice = Math.ceil(Math.random() * this.config.likelyHood.denominator);
if (this.config.likelyHood.numerator <= rolledDice) {
return;
}
video.currentTime = 0;
this.show();
video.play();
setTimeout(function () {
self.hide();
//update the Domvideo
}, this.duration * 1000);
},
notificationReceived: function (notification) {
if (notification === 'DOM_OBJECTS_CREATED') {
this.hide();
if (this.intervalTimer === undefined) {
var self = this;
this.intervalTimer = setInterval(self.showVid.bind(this), this.config.interval);
}
}
}
});