Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const nameTypes = {
+ character: {
+ prefixes: ['Al', 'El', 'Kai', 'Zar', 'Ry', 'Mar'],
+ middleParts: ['an', 'en', 'in', 'on', 'ar', 'or'],
+ suffixes: ['der', 'ton', 'ley', 'son', 'wen', 'thy']
+ },
+ business: {
+ prefixes: ['Nova', 'Peak', 'Prime', 'Elite', 'Core', 'Apex'],
+ middleParts: ['tech', 'mind', 'shift', 'wave', 'flux', 'sync'],
+ suffixes: ['hub', 'labs', 'works', 'corp', 'pro', 'max']
+ },
+ product: {
+ prefixes: ['i', 'eco', 'smart', 'pro', 'ultra', 'meta'],
+ middleParts: ['flex', 'flow', 'pulse', 'spark', 'dash', 'zen'],
+ suffixes: ['x', 'plus', 'pro', 'lite', 'max', 'go']
+ },
+ fantasy: {
+ prefixes: ['Aether', 'Frost', 'Storm', 'Dawn', 'Night', 'Star'],
+ middleParts: ['blade', 'heart', 'soul', 'wind', 'fire', 'light'],
+ suffixes: ['bane', 'forge', 'weave', 'born', 'shade', 'glow']
+ }
+ };
+
+ const generateBtn = document.getElementById('generate');
+ const copyBtn = document.getElementById('copy');
+ const nameTypeSelect = document.getElementById('nameType');
+ const generatedNameElement = document.getElementById('generatedName');
+ const nameHistory = document.getElementById('nameHistory');
+
+ const generateName = () => {
+ const type = nameTypeSelect.value;
+ const gender = document.querySelector('input[name="gender"]:checked').value;
+ const parts = nameTypes[type];
+
+ const prefix = parts.prefixes[Math.floor(Math.random() * parts.prefixes.length)];
+ const middle = parts.middleParts[Math.floor(Math.random() * parts.middleParts.length)];
+ const suffix = parts.suffixes[Math.floor(Math.random() * parts.suffixes.length)];
+
+ let name = '';
+ if (Math.random() > 0.5) {
+ name = `${prefix}${middle}`;
+ } else {
+ name = `${prefix}${middle}${suffix}`;
+ }
+
+ if (gender === 'feminine' && type === 'character') {
+ name += 'a';
+ }
+
+ return name;
+ };
+
+ generateBtn.addEventListener('click', () => {
+ const name = generateName();
+ generatedNameElement.textContent = name;
+
+ const historyItem = document.createElement('li');
+ historyItem.textContent = name;
+ nameHistory.insertBefore(historyItem, nameHistory.firstChild);
+
+ if (nameHistory.children.length > 5) {
+ nameHistory.removeChild(nameHistory.lastChild);
+ }
+ });
+
+ copyBtn.addEventListener('click', () => {
+ navigator.clipboard.writeText(generatedNameElement.textContent)
+ .then(() => {
+ copyBtn.classList.add('copied');
+ setTimeout(() => copyBtn.classList.remove('copied'), 1000);
+ });
+ });
+ });