This commit is contained in:
David Ralph 2019-01-21 18:06:35 +00:00
parent f14e286f76
commit a532449261
3 changed files with 12 additions and 26 deletions

View File

@ -1,11 +1,3 @@
const util = require('./utility.js');
const message = require('./message.js');
const quotes = require('./quotes.js');
const background = require('./background.js');
const codes = require('./codes.js');
let nal = navigator.language;
/*
@ -24,6 +16,14 @@ let nal = navigator.language;
*/
const util = require('./utility.js');
const message = require('./message.js');
const quotes = require('./quotes.js');
const background = require('./background.js');
const codes = require('./codes.js');
let nal = navigator.language;
module.exports = class Functions {
static setDaytimeMessage() {
if (util.contains.call(codes.itcodes, nal)) message.itMessageSet(); //Italian

View File

@ -21,13 +21,10 @@ const { setHTMLContent } = require('./utility.js');
module.exports = class Message {
// English
static engMessageSet() {
let hour = new Date().getHours(); // Get the current hour
let time = 'Good evening'; // Set the default time string to "Good evening"
if (hour < 12) time = 'Good morning'; //If it's before 12am, set the time string to "Good morning"
else if (hour > 18) time = 'Good afternoon'; //If it's after 6pm, set the time string to "Good afternoon"
setHTMLContent('.greeting', time); // Write the string contents to the HTML
}
@ -35,9 +32,7 @@ module.exports = class Message {
static itMessageSet() {
let hour = new Date().getHours(); // Get the current hour
let time = 'Buongiorno';
if (hour > 18) time = 'Buonasera'; //In Italian there is just Buongiorno or Buonasera
setHTMLContent('.greeting', time); // Write the string contents to the HTML
}
@ -45,10 +40,8 @@ module.exports = class Message {
static nlMessageSet() {
let hour = new Date().getHours(); // Get the current hour
let time = 'Goedemiddag'; // Set the default time string to "Good evening"
if (hour < 12) time = 'Goedemorgen'; //If it's before 12am, set the time string to "Good morning"
else if (hour > 18) time = 'Goedenavond'; //If it's after 6pm, set the time string to "Good afternoon"
setHTMLContent('.greeting', time); // Write the string contents to the HTML
}
@ -56,10 +49,8 @@ module.exports = class Message {
static frMessageSet() {
let hour = new Date().getHours(); // Get the current hour
let time = 'Bonsoir'; // Set the default time string to "Good evening"
if (hour < 12) time = 'Bonjour'; //If it's before 12am, set the time string to "Good morning"
else if (hour > 18) time = 'Bonne après-midi'; //If it's after 6pm, set the time string to "Good afternoon"
setHTMLContent('.greeting', time); // Write the string contents to the HTML
}
@ -67,10 +58,8 @@ module.exports = class Message {
static spMessageSet() {
let hour = new Date().getHours(); // Get the current hour
let time = 'Buenas Tardes'; // Set the default time string to "Good evening"
if (hour < 12) time = 'Buenos Días'; // If it's before 12am, set the time string to "Good morning"
else if (hour > 20) time = 'Buenas Noches'; // If it's after 6pm, set the time string to "Good afternoon"
setHTMLContent('.greeting', time); // Write the string contents to the HTML
}
}

View File

@ -19,22 +19,22 @@
module.exports = class Util {
// format time
static formatTimeUnit(unit) {
return unit < 10 ? '0' + unit : unit
return unit < 10 ? '0' + unit : unit;
};
// setHTMLContent is the kind of function that is referred to as a 'wrapper'
static setHTMLContent(selector, content) {
return document.querySelector(selector).innerHTML = content
return document.querySelector(selector).innerHTML = content;
};
// get random item
static getRandIndex(array) {
return Math.floor(Math.random() * (array.length - 1))
return Math.floor(Math.random() * (array.length - 1));
}
// pick random from array
static pickFromArray(array) {
return array[Math.floor(Math.random() * (array.length - 1))]
return array[Math.floor(Math.random() * (array.length - 1))];
};
static contains(needle) {
@ -46,16 +46,13 @@ module.exports = class Util {
indexOf = (needle) => {
let i = -1,
index = -1;
for (i = 0; i < this.length; i++) {
let item = this[i];
if ((findNaN && item !== item) || item === needle) {
index = i;
break;
}
}
return index;
};
}