mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-08-21 04:45:17 +00:00
Initial commit of V2.
This commit is contained in:
67
modules/clock/clock.js
Normal file
67
modules/clock/clock.js
Normal file
@@ -0,0 +1,67 @@
|
||||
/* global Log, Module, moment, config */
|
||||
|
||||
/* Magic Mirror
|
||||
* Module: Clock
|
||||
*
|
||||
* By Michael Teeuw http://michaelteeuw.nl
|
||||
* MIT Licensed.
|
||||
*/
|
||||
|
||||
Module.create({
|
||||
|
||||
// Module config defaults.
|
||||
defaults: {
|
||||
timeFormat: 24,
|
||||
displaySeconds: true,
|
||||
},
|
||||
|
||||
// Define required scripts.
|
||||
getScripts: function() {
|
||||
return ['moment.js'];
|
||||
},
|
||||
|
||||
// Define start sequence.
|
||||
start: function() {
|
||||
Log.info('Starting module: ' + this.name);
|
||||
|
||||
// Schedule update interval.
|
||||
var self = this;
|
||||
setInterval(function() {
|
||||
self.updateDom();
|
||||
}, 1000);
|
||||
|
||||
// Set locale.
|
||||
moment.locale(config.language);
|
||||
},
|
||||
|
||||
|
||||
// Override dom generator.
|
||||
getDom: function() {
|
||||
// Create wrappers.
|
||||
var wrapper = document.createElement("div");
|
||||
var dateWrapper = document.createElement("div");
|
||||
var timeWrapper = document.createElement("div");
|
||||
var secondsWrapper = document.createElement("sup");
|
||||
|
||||
// Style Wrappers
|
||||
dateWrapper.className = "date normal medium";
|
||||
timeWrapper.className = "time bright large light";
|
||||
secondsWrapper.className = "dimmed";
|
||||
|
||||
// Set content of wrappers.
|
||||
dateWrapper.innerHTML = moment().format('dddd, LL');
|
||||
timeWrapper.innerHTML = moment().format((this.config.timeFormat === 24) ? 'HH:mm' : ('hh:mm'));
|
||||
secondsWrapper.innerHTML = moment().format('ss');
|
||||
|
||||
// Combine wrappers.
|
||||
wrapper.appendChild(dateWrapper);
|
||||
wrapper.appendChild(timeWrapper);
|
||||
if (this.config.displaySeconds) {
|
||||
timeWrapper.appendChild(secondsWrapper);
|
||||
}
|
||||
|
||||
// Return the wrapper to the dom.
|
||||
return wrapper;
|
||||
}
|
||||
});
|
||||
|
123
modules/compliments/compliments.js
Normal file
123
modules/compliments/compliments.js
Normal file
@@ -0,0 +1,123 @@
|
||||
/* global Log, Module, moment */
|
||||
|
||||
/* Magic Mirror
|
||||
* Module: Compliments
|
||||
*
|
||||
* By Michael Teeuw http://michaelteeuw.nl
|
||||
* MIT Licensed.
|
||||
*/
|
||||
|
||||
Module.create({
|
||||
|
||||
// Module config defaults.
|
||||
defaults: {
|
||||
compliments: {
|
||||
morning: [
|
||||
'Good morning, handsome!',
|
||||
'Enjoy your day!',
|
||||
'How was your sleep?'
|
||||
],
|
||||
afternoon: [
|
||||
'Hello, beauty!',
|
||||
'You look sexy!',
|
||||
'Looking good today!'
|
||||
],
|
||||
evening: [
|
||||
'Wow, you look hot!',
|
||||
'You look nice!',
|
||||
'Hi, sexy!'
|
||||
]
|
||||
},
|
||||
updateInterval: 30000,
|
||||
fadeSpeed: 4000
|
||||
},
|
||||
|
||||
// Define required scripts.
|
||||
getScripts: function() {
|
||||
return ['moment.js'];
|
||||
},
|
||||
|
||||
// Define start sequence.
|
||||
start: function() {
|
||||
Log.info('Starting module: ' + this.name);
|
||||
|
||||
this.lastComplimentIndex = -1;
|
||||
|
||||
// Schedule update timer.
|
||||
var self = this;
|
||||
setInterval(function() {
|
||||
self.updateDom(self.config.fadeSpeed);
|
||||
}, this.config.updateInterval);
|
||||
},
|
||||
|
||||
|
||||
/* randomIndex(compliments)
|
||||
* Generate a random index for a list of compliments.
|
||||
*
|
||||
* argument compliments Array<String> - Array with compliments.
|
||||
*
|
||||
* return Number - Random index.
|
||||
*/
|
||||
randomIndex: function(compliments) {
|
||||
if (compliments.length === 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
var generate = function() {
|
||||
return Math.floor(Math.random() * compliments.length);
|
||||
};
|
||||
|
||||
var complimentIndex = generate();
|
||||
|
||||
while (complimentIndex === this.lastComplimentIndex) {
|
||||
complimentIndex = generate();
|
||||
}
|
||||
|
||||
this.lastComplimentIndex = complimentIndex;
|
||||
|
||||
return complimentIndex;
|
||||
},
|
||||
|
||||
/* complimentArray()
|
||||
* Retrieve an array of compliments for the time of the day.
|
||||
*
|
||||
* return compliments Array<String> - Array with compliments for the time of the day.
|
||||
*/
|
||||
complimentArray: function() {
|
||||
var hour = moment().hour();
|
||||
|
||||
if (hour >= 3 && hour < 12) {
|
||||
return this.config.compliments.morning;
|
||||
} else if (hour >= 12 && hour < 17) {
|
||||
return this.config.compliments.afternoon;
|
||||
} else {
|
||||
return this.config.compliments.evening;
|
||||
}
|
||||
},
|
||||
|
||||
/* complimentArray()
|
||||
* Retrieve a random compliment.
|
||||
*
|
||||
* return compliment string - A compliment.
|
||||
*/
|
||||
randomCompliment: function() {
|
||||
var compliments = this.complimentArray();
|
||||
var index = this.randomIndex(compliments);
|
||||
|
||||
return compliments[index];
|
||||
},
|
||||
|
||||
// Override dom generator.
|
||||
getDom: function() {
|
||||
var complimentText = this.randomCompliment();
|
||||
|
||||
var compliment = document.createTextNode(complimentText);
|
||||
var wrapper = document.createElement("div");
|
||||
wrapper.className = 'thin xlarge';
|
||||
wrapper.appendChild(compliment);
|
||||
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
});
|
||||
|
27
modules/helloworld/helloworld.js
Normal file
27
modules/helloworld/helloworld.js
Normal file
@@ -0,0 +1,27 @@
|
||||
/* global Module */
|
||||
|
||||
/* Magic Mirror
|
||||
* Module: HelloWorld
|
||||
*
|
||||
* By Michael Teeuw http://michaelteeuw.nl
|
||||
* MIT Licensed.
|
||||
*/
|
||||
|
||||
Module.create({
|
||||
|
||||
// Default module config.
|
||||
defaults: {
|
||||
text: "Hello World!",
|
||||
classes: "normal medium"
|
||||
},
|
||||
|
||||
// Override dom generator.
|
||||
getDom: function() {
|
||||
var wrapper = document.createElement("div");
|
||||
wrapper.className = this.config.classes;
|
||||
wrapper.innerHTML = this.config.text;
|
||||
|
||||
return wrapper;
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user