mirror of
https://github.com/mue/mue.git
synced 2026-06-08 14:10:42 +02:00
Found a way for making code cleaner and shorter
This commit is contained in:
@@ -29,17 +29,47 @@
|
|||||||
// further reading:
|
// further reading:
|
||||||
// https://eloquentjavascript.net/05_higher_order.html
|
// https://eloquentjavascript.net/05_higher_order.html
|
||||||
|
|
||||||
|
var contains = function(needle) {
|
||||||
|
|
||||||
|
var findNaN = needle !== needle;
|
||||||
|
var indexOf;
|
||||||
|
|
||||||
|
if(!findNaN && typeof Array.prototype.indexOf === 'function') {
|
||||||
|
indexOf = Array.prototype.indexOf;
|
||||||
|
} else {
|
||||||
|
indexOf = function(needle) {
|
||||||
|
var i = -1, index = -1;
|
||||||
|
|
||||||
|
for(i = 0; i < this.length; i++) {
|
||||||
|
var item = this[i];
|
||||||
|
|
||||||
|
if((findNaN && item !== item) || item === needle) {
|
||||||
|
index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return index;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return indexOf.call(this, needle) > -1;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
let nal = navigator.language;
|
let nal = navigator.language;
|
||||||
|
|
||||||
|
let itcodes = ['it', 'it-IT', 'it-CH'];
|
||||||
|
let nlcodes = ['nl', 'nl-BE'];
|
||||||
|
let frcodes = ['fr', 'fr-BE', 'fr-CA', 'fr-FR', 'fr-LU', 'fr-MC', 'fr-CH'];
|
||||||
|
let ptcodes = ['pt', 'pt-BR'];
|
||||||
|
|
||||||
function setDaytimeMessage () {
|
function setDaytimeMessage () {
|
||||||
if (nal === 'it' || nal === 'it-IT' || nal === 'it-CH') itaMessageSet(); //Italian
|
|
||||||
else if (nal === 'nl'|| nal === 'nl-BE') nlMessageSet(); //Dutch
|
|
||||||
|
|
||||||
else if (nal === 'fr' || nal === 'fr-BE'|| nal === 'fr-CA'||
|
if ( contains.call(itcodes, nal) ) itMessageSet(); //Italian
|
||||||
nal === 'fr-FR'|| nal === 'fr-LU'|| nal === 'fr-MC'||
|
else if ( contains.call(nlcodes, nal) ) nlMessageSet(); //Dutch
|
||||||
nal === 'fr-CH') frMessageSet(); //French
|
else if ( contains.call(frcodes, nal) ) frMessageSet(); //French
|
||||||
|
else if ( contains.call(ptcodes, nal) ) ptMessageSet(); //Portuguese
|
||||||
else if (nal === 'pt' || nal === 'pt-BR') ptMessageSet(); //Portuguese
|
|
||||||
else engMessageSet(); //English
|
else engMessageSet(); //English
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -321,7 +351,7 @@ function engMessageSet() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Italian
|
// Italian
|
||||||
function itaMessageSet() {
|
function itMessageSet() {
|
||||||
let hour = new Date().getHours(); // Get the current hour
|
let hour = new Date().getHours(); // Get the current hour
|
||||||
let time = 'Buongiorno';
|
let time = 'Buongiorno';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user