Skip to content

Commit

Permalink
Format JS file with Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhaddil committed May 3, 2024
1 parent d035881 commit 3cea55e
Showing 1 changed file with 58 additions and 51 deletions.
109 changes: 58 additions & 51 deletions JS/glyphgeneratorV3.js
Original file line number Diff line number Diff line change
@@ -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) => `<span id="glyph${i}" class="glyph"></span>`).join('');

glyphOutput.innerHTML = Array.from(
{ length: 12 },
(_, i) => `<span id="glyph${i}" class="glyph"></span>`
).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();
Expand All @@ -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();
}
);

0 comments on commit 3cea55e

Please sign in to comment.