Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
juicebct committed Feb 2, 2025
0 parents commit 19ffe0b
Show file tree
Hide file tree
Showing 16 changed files with 783 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
30 changes: 30 additions & 0 deletions addons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// Some addtional features for website like: copying nicknames to clipboard, dropdown lists logic.
//

// Function to copy nickname
function copyNickname() {
const nicknameField = document.getElementById("nickname");
nicknameField.select();
document.execCommand("copy");
alert("Nickname copied: " + nicknameField.value);
}


// Dropdown lists (for language and nationality selection)
function toggleDropdown(selector) {
document.querySelector(selector).classList.toggle("active");
}

document.addEventListener("click", function (event) {
document.querySelectorAll(".dropdown").forEach(dropdown => {
if (!dropdown.contains(event.target)) {
dropdown.classList.remove("active");
}
});
});

function changeSelection(selector, targetId, value) {
document.getElementById(targetId).textContent = value;
document.querySelector(selector).classList.remove("active");
}
45 changes: 45 additions & 0 deletions generator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// The logic for generating character nicknames is described here.
//

// Loading data from the file names.json
let namesData = {};

fetch("names.json")
.then(response => response.json())
.then(data => namesData = data)
.catch(error => console.error("ERROR: Data loading error:", error));

// Main function
function generateNickname() {
// Getting user selection...
const gender = document.querySelector("input[name='gender']:checked")?.id;
const nationality = document.getElementById("selected-nationality").textContent.toLowerCase();

// Some checks so that the user cannot miss a choice
if (!gender) {
alert("ERROR: Please select the character's gender.");
return;
}
if (nationality === "select option") {
alert("ERROR: Please select the character's nationality.");
return;
}

// Getting arrays of names and surnames...
const firstNames = namesData[gender]?.[nationality]?.first_names;
const lastNames = namesData[gender]?.[nationality]?.last_names;

// Checking for availability of data for selected parameters (does the file names.json contain similar parameters and data for them)
if (!firstNames || !lastNames) {
alert("ERROR: No data for such parameters.");
return;
}

// Random generation
const randomFirstName = firstNames[Math.floor(Math.random() * firstNames.length)];
const randomLastName = lastNames[Math.floor(Math.random() * lastNames.length)];

// Updating nickname in nicknamebox
document.getElementById("nickname").value = `${randomFirstName}_${randomLastName}`;
}
3 changes: 3 additions & 0 deletions icons/Globe.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions icons/person-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions images/Logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions images/female-icon-mobile.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions images/female-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions images/male-icon-mobile.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 19ffe0b

Please sign in to comment.