From 3cea55e1237ddd2dc1eb4cdb64e8391dc06d867b Mon Sep 17 00:00:00 2001 From: Muhaddil <151466679+Muhaddil@users.noreply.github.com> Date: Fri, 3 May 2024 15:28:40 +0200 Subject: [PATCH] Format JS file with Prettier --- JS/glyphgeneratorV3.js | 109 ++++++++++++++++++++++------------------- 1 file changed, 58 insertions(+), 51 deletions(-) diff --git a/JS/glyphgeneratorV3.js b/JS/glyphgeneratorV3.js index 82f908b..923411f 100644 --- a/JS/glyphgeneratorV3.js +++ b/JS/glyphgeneratorV3.js @@ -1,34 +1,38 @@ // Function to generate a random glyph -export const randomGlyph = () => '0123456789ABCDEF'[Math.floor(Math.random() * 16)]; +export const randomGlyph = () => + "0123456789ABCDEF"[Math.floor(Math.random() * 16)]; // Function to generate random glyphs export const generateGlyphs = () => { // Generate a string of random glyphs, always starting with '0' - const glyphs = '0' + Array.from({length: 11}, randomGlyph).join(''); + const glyphs = "0" + Array.from({ length: 11 }, randomGlyph).join(""); // Return the glyphs return glyphs; -} +}; export const displayRandomGlyphs = () => { // Get the button and output elements from the DOM - const generateButton = document.getElementById('generateButton'); - const glyphOutput = document.getElementById('glyphOutput'); - + const generateButton = document.getElementById("generateButton"); + const glyphOutput = document.getElementById("glyphOutput"); + // Disable the button generateButton.disabled = true; - + // Generate the glyphs const glyphs = generateGlyphs(); - + // Display the glyphs in the output elements // Each glyph is a span with the class 'glyph' and a unique id - glyphOutput.innerHTML = Array.from({length: 12}, (_, i) => ``).join(''); - + glyphOutput.innerHTML = Array.from( + { length: 12 }, + (_, i) => `` + ).join(""); + // Add the animation to each glyph - glyphs.split('').forEach((glyph, i) => { + glyphs.split("").forEach((glyph, i) => { setTimeout(() => { const glyphElement = document.getElementById(`glyph${i}`); - glyphElement.classList.add('spin'); + glyphElement.classList.add("spin"); // Change the glyph every 100ms while it's spinning const intervalId = setInterval(() => { glyphElement.textContent = randomGlyph(); @@ -45,65 +49,68 @@ export const displayRandomGlyphs = () => { }, 1000); }, i * 200); // Delay the start of each animation }); -} +}; // Make the displayRandomGlyphs function globally accessible window.displayRandomGlyphs = displayRandomGlyphs; // Function to change language window.changeLanguage = () => { - const lang = document.getElementById('lang').value; + const lang = document.getElementById("lang").value; i18next.changeLanguage(lang); - localStorage.setItem('i18nextLng', lang); - $('body').localize(); -} + localStorage.setItem("i18nextLng", lang); + $("body").localize(); +}; // Function to populate the language options const populateLanguageOptions = () => { - const select = document.getElementById('lang'); + const select = document.getElementById("lang"); const languageNames = { - en: 'English', - es: 'Español' + en: "English", + es: "Español", // You can add more languages here }; Object.keys(i18next.options.resources).forEach((lang) => { - const option = document.createElement('option'); + const option = document.createElement("option"); option.value = lang; option.text = languageNames[lang]; select.add(option); }); -} +}; // Initialize i18next -i18next.init({ - lng: localStorage.getItem('i18nextLng') || navigator.language || 'en', - resources: { - en: { - translation: { - title: "NMS Glyph Generator", - header: "NMS Glyph Generator", - button: "Generate Glyphs" - } +i18next.init( + { + lng: localStorage.getItem("i18nextLng") || navigator.language || "en", + resources: { + en: { + translation: { + title: "NMS Glyph Generator", + header: "NMS Glyph Generator", + button: "Generate Glyphs", + }, + }, + es: { + translation: { + title: "Generador de Glifos NMS", + header: "Generador de Glifos NMS", + button: "Generar Glifos", + }, + }, + // You can add more languages here }, - es: { - translation: { - title: "Generador de Glifos NMS", - header: "Generador de Glifos NMS", - button: "Generar Glifos" - } - } - // You can add more languages here - } -}, (err, t) => { - // Initialize the jquery-i18next library - jqueryI18next.init(i18next, $); - // Translate the entire body - $('body').localize(); + }, + (err, t) => { + // Initialize the jquery-i18next library + jqueryI18next.init(i18next, $); + // Translate the entire body + $("body").localize(); - // This selects the correct language option in the select - const lang = i18next.language; - document.getElementById('lang').value = lang; + // This selects the correct language option in the select + const lang = i18next.language; + document.getElementById("lang").value = lang; - // This autopopulates the language options in the select - populateLanguageOptions(); -}); + // This autopopulates the language options in the select + populateLanguageOptions(); + } +);