From 007f43564957052214cbfad5ca61aedf1af0226d Mon Sep 17 00:00:00 2001 From: Yanderella! Date: Tue, 30 Oct 2018 09:49:06 +0100 Subject: [PATCH 1/4] Found a way for making code cleaner and shorter --- assets/js/index.js | 48 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/assets/js/index.js b/assets/js/index.js index c5043b94..71e20176 100644 --- a/assets/js/index.js +++ b/assets/js/index.js @@ -29,17 +29,47 @@ // further reading: // 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 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 () { - 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'|| - nal === 'fr-FR'|| nal === 'fr-LU'|| nal === 'fr-MC'|| - nal === 'fr-CH') frMessageSet(); //French - - else if (nal === 'pt' || nal === 'pt-BR') ptMessageSet(); //Portuguese + + if ( contains.call(itcodes, nal) ) itMessageSet(); //Italian + else if ( contains.call(nlcodes, nal) ) nlMessageSet(); //Dutch + else if ( contains.call(frcodes, nal) ) frMessageSet(); //French + else if ( contains.call(ptcodes, nal) ) ptMessageSet(); //Portuguese else engMessageSet(); //English }; @@ -321,7 +351,7 @@ function engMessageSet() { } // Italian -function itaMessageSet() { +function itMessageSet() { let hour = new Date().getHours(); // Get the current hour let time = 'Buongiorno'; From 44d5c7c6c4b0da4e80e3df82524ad9d9e5a52b75 Mon Sep 17 00:00:00 2001 From: Yanderella! Date: Tue, 30 Oct 2018 09:52:55 +0100 Subject: [PATCH 2/4] Update index.js --- assets/js/index.js | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/assets/js/index.js b/assets/js/index.js index 71e20176..0e53e130 100644 --- a/assets/js/index.js +++ b/assets/js/index.js @@ -1,15 +1,25 @@ /* - __ __ - | \/ | - | \ / |_ _ ___ - | |\/| | | | |/ _ \ - | | | | |_| | __/ - |_| |_|\__,_|\___| - ------------------- - Copyright 2018 Dave R (ohlookitsderpy) - Licensed under MIT - Special thanks to contributors! <3 - GitHub: https://github.com/ohlookitsderpy/Mue +/* +███████████████████████████████████████████████████████████ +█ █╗ +█ ███╗ ███╗██╗ ██╗███████╗ █║ +█ ████╗ ████║██║ ██║██╔════╝ █║ +█ ██╔████╔██║██║ ██║█████╗ █║ +█ ██║╚██╔╝██║██║ ██║██╔══╝ █║ +█ ██║ ╚═╝ ██║╚██████╔╝███████╗ █║ +█ ╚═╝ ╚═╝ ╚═════╝ ╚══════╝ █║ +█ █║ +█ Copyright 2018 Dave R (ohlookitsderpy) █║ +█ Licensed under MIT █║ +█ GitHub: https://github.com/ohlookitsderpy/Mue █║ +█ █║ +█ Spanish Translation made by: Pepehound █║ +█ Portuguese Translation made by: Candystick █║ +█ █║ +█ Special thanks to contributors! <3 █║ +███████████████████████████████████████████████████████████║ + ╚═════════════════════════════════════════════════════════╝ +*/ */ // start a separate function for each of the things that we need to do From 22567cdd80ed7cf89fd21d60b471cfb904345829 Mon Sep 17 00:00:00 2001 From: Yanderella! Date: Tue, 30 Oct 2018 09:53:32 +0100 Subject: [PATCH 3/4] Update index.html --- index.html | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/index.html b/index.html index 930cb465..3aaed1dd 100644 --- a/index.html +++ b/index.html @@ -1,15 +1,22 @@ From a951e91c790f25791e852e88ee6855068ba7b7cc Mon Sep 17 00:00:00 2001 From: Yanderella! Date: Wed, 31 Oct 2018 19:40:54 +0100 Subject: [PATCH 4/4] Update index.js --- assets/js/index.js | 110 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 98 insertions(+), 12 deletions(-) diff --git a/assets/js/index.js b/assets/js/index.js index 0e53e130..dc48271d 100644 --- a/assets/js/index.js +++ b/assets/js/index.js @@ -1,5 +1,4 @@ /* -/* ███████████████████████████████████████████████████████████ █ █╗ █ ███╗ ███╗██╗ ██╗███████╗ █║ @@ -20,7 +19,6 @@ ███████████████████████████████████████████████████████████║ ╚═════════════════════════════════════════════════════════╝ */ -*/ // start a separate function for each of the things that we need to do @@ -39,6 +37,20 @@ // further reading: // https://eloquentjavascript.net/05_higher_order.html +//From cirnornd.js +function randomInt(min, max) { + let badArg = new Error("Bad args ;-;"); + + try { + if( typeof min != 'number' || typeof max != 'number' ) throw badArg; + min += 1 + return Math.floor(Math.random() * (max - min + 1)) + min; + + } catch (error) { + return error; + } +} + var contains = function(needle) { var findNaN = needle !== needle; @@ -73,17 +85,19 @@ 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']; +let spcodes = ['es', 'es-AR', 'es-BO', 'es-CL', 'es-CO', 'es-CR', 'es-DO', + 'es-EC', 'es-ES', 'es-GT', 'es-HN', 'es-MX', 'es-NI', 'es-PA', + 'es-PE', 'es-PR', 'es-PY', 'es-SV', 'es-UY', 'es-VE']; function setDaytimeMessage () { - if ( contains.call(itcodes, nal) ) itMessageSet(); //Italian else if ( contains.call(nlcodes, nal) ) nlMessageSet(); //Dutch else if ( contains.call(frcodes, nal) ) frMessageSet(); //French else if ( contains.call(ptcodes, nal) ) ptMessageSet(); //Portuguese - else engMessageSet(); //English + else if ( contains.call(spcodes, nal) ) spMessageSet(); + else engMessageSet(); //English }; - function setRandomBackground () { let backgroundClasses = [ @@ -138,7 +152,7 @@ function setRandomQuote () { // big-enough objects — such as each of the quotes — may be... // ...separated by a new line each for clarity - let quotes = [ + /*let quotes = [ { eng: 'Time goes on. So whatever you’re going to do, do it. Do it now. Don’t wait.', ita: 'Il tempo passa. Quindi qualunque cosa che farai, falla. Falla ora. Non aspettare', @@ -220,14 +234,74 @@ function setRandomQuote () { ita: "La vita è come andare in bicicletta. Per tenerti in equilibrio, devi continuare a muoverti", pt: "", author: 'Albert Einstein'} - ], - quote = pickFromArray(quotes); + ],*/ + + let quotes = { + ita: [ + 'Il tempo passa. Quindi qualunque cosa che farai, falla. Falla ora. Non aspettare', + 'Tutti i nostri sogni possono diventare reali, se abbiamo il coraggio di seguirli.', + 'Non importa quanto lentamente vai fino a quando non ti fermi', + 'Credi in te stesso. Sei più coraggioso di quanto pensi, più talentuoso di quanto credi, e capace più di quanto puoi immaginare.', + 'Se ci credi funzionerà, vedrai delle opportunità. Se non ci credi, vedrai solamente ostacoli', + 'Tutti i tuoi desideri sono opposti alla paura', + 'Il successo non è la fine, il fallimento non è fatale: è il coraggio per continuare quello che conta.', + "C'è solo una cosa che fa i sogni impossibili: la paura di fallire", + 'Il vero successo nella tua vita inizia solo quando fai il sacrificio per diventare eccellente a quello che ami.', + "Credi in te stesso, sfida i tuoi problemi, scava nel profondo del tuo io per sconfiggere le tue paure. Mai arrendersi per qualcun'altro. Tu devi continuare.", + "Troppe persone non vivono i loro sogni per vivere nelle loro paure", + "Tempi difficili non fanno eroi. È durante i tempi duri che \"l'eroe\" in noi viene rivelato.", + "Se puoi sintonizzare sul tuo senso e allinearti a quest'ultimo, impostando i tuoi obiettivi in modo che la tua visione sia un'espressione di quel senso, La tua vita scorre molto più facilmente", + "Qualunque cosa la mente può immaginare e crederese, si può realizzare", + "Non desiderare che fosse stato più facile. Desidera che tu fossi stato migliore.", + "Un campione si definisce non dalle sue vittorie ma da come recupera quando cade", + "La motivazione viene dal lavorare so cose che amiamo", + "Con il giusto tipo di allenamento e determinazione puoi fare tutto", + "Alcune persone cercano un posto indimenticabile. Altre lo transformano in un posto mozzafiato.", + "La vita è come andare in bicicletta. Per tenerti in equilibrio, devi continuare a muoverti" + ], + spa: [ + "El tiempo continúa. Así que lo que sea que vayas a hacer, hazlo. Hazlo ahora. No esperes", + "Todos nuestros sueños pueden hacerse realidad, si tenemos el coraje de perseguirlos.", + "No importa qué tan lento vayas, siempre y cuando no te detengas.", + "Cree en ti mismo. Eres más valiente de lo que crees, más talentoso de lo que sabes y capaz de más de lo que imaginas.", + "Si crees que funcionará, verás oportunidades. Si crees que no, verás obstáculos ", + "Todo lo que siempre has querido está al otro lado del miedo", + "El éxito no es definitivo, el fracaso no es fatal: el coraje para continuar es lo que cuenta", + "Solo hay una cosa que hace que un sueño sea imposible de lograr: el miedo al fracaso", + "Tu verdadero éxito en la vida comienza solo cuando te comprometes a ser excelente en lo que haces", + "Cree en ti mismo, asume tus desafíos, excava profundo dentro de ti mismo para vencer tus miedos. Nunca dejes que nadie te derribe. Tienes que seguir adelante.", + "Muchos de nosotros no estamos viviendo nuestros sueños porque estamos viviendo nuestros miedos", + "Los tiempos difíciles no crean héroes. Es durante los momentos difíciles en que se revela el héroe dentro de nosotros.", + "Si puedes sincornizarte con tu propósito, y realmente alinearte con él, estableciendo metas para que tu visión sea una expresión de ese propósito, entonces la vida fluye mucho más fácilmente", + "Lo que la mente pueda concebir y creer, lo puede lograr", + "No desees que sea fácil. Desea ser mejor.", + "Un campeón se define no por sus victorias, sino por cómo pueden recuperarse cuando caen", + "La motivación viene de trabajar en cosas que nos importan", + "Con el entrenamiento y la determinación adecuados, puedes lograr cualquier cosa", + "Algunas personas buscan un lugar hermoso. Otras, hacen un lugar hermoso.", + ], + pt: [ + "O tempo continua. Então o que quer que você vai fazer,faça. Faça agora. Não espere.", + "Todos os sonhos podem virar verdade,se tivermos a coragem de persegui-los.", + "Não importa o quão devagar você for,desde que você não pare.", + "Acredite em si mesmo. Você é mais corajoso que pensa,mais talentoso que sabe,e capaz de mais que imagina.", + "Se você acredita que vai dar certo,você verá oportunidades. Se você acredita que não vai,você vera obstáculos.", + ], + authors: ['Robert De Niro', 'Walt Disney', 'Confucius', 'Roy T. Bennett', 'Wayne Dyer', 'George Addair', 'Winston Churchill', 'Paulo Coelho', + 'Brian Tracy', 'Chantal Sutherland', 'Les Brown', 'Bob Riley', 'Jack Canfield', 'Napoleon Hill', 'Jim Rohn', 'Serena Williams', + 'Sheryl Sandberg', 'Reese Witherspoon', 'Hazrat Inayat Khan', 'Albert Einstein'] - if (nal === 'it' || nal === 'it-IT'|| nal === 'it-CH') setHTMLContent('blockquote', quote.ita); - else if( nal === 'pt' || nal === 'pt-BR') setHTMLContent('blockquote', quote.pt || quote.eng) - else setHTMLContent('blockquote', quote.eng); + }; + let id = getRandIndex( quotes.authors ); + + //nal = navigator.language + + if ( contains.call(itcodes, nal) ) setHTMLContent('blockquote', quotes.ita[id]); + else if( contains.call(ptcodes, nal) ) setHTMLContent('blockquote', quotes.pt[id] || quotes.eng[id]); + else if( contains.call(spcodes, nal) ) setHTMLContent('blockquote', quotes.spa[id]); + else setHTMLContent('blockquote', quotes.eng[id]); - setHTMLContent('cite', quote.author); + setHTMLContent('cite', quotes.authors[id]); // little treats of visual alignment, for code beauty's sake @@ -336,6 +410,8 @@ function formatTimeUnit (unit) { return unit < 10 ? '0' + unit : unit }; function setHTMLContent (selector, content) { return document.querySelector(selector) .innerHTML = content }; +function getRandIndex(array) { return Math.floor(Math.random() * (array.length - 1)) } + function pickFromArray(array) { return array[Math.floor(Math.random() * (array.length - 1))] }; // Disable right click @@ -394,3 +470,13 @@ function frMessageSet() { setHTMLContent('.greeting', time); // Write the string contents to the HTML } + +function 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 +}