JSFiddle - React, Tailwind, and code Playground
by vvv vvvv
HTML
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Générateur d'UID</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<h1>Générateur d'UID</h1>
<label for="length">Longueur de l'UID :</label>
<input type="number" id="length" min="1" value="8">
<br>
<button onclick="generateUID()">Générer l'UID</button>
<div class="result-container">
<p id="uid">Votre UID apparaîtra ici</p>
<p class="message" id="message">Copié!</p>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
CSS
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #ececec;
}
.container {
background: #ffffff;
padding: 30px;
border-radius: 15px;
box-shadow: 0 6px 15px rgba(0, 0, 0, 0.2);
text-align: center;
width: 350px; /* Width is fixed */
position: relative;
border: 2px solid #007bff; /* Stylish border */
}
h1 {
color: #007bff;
margin-bottom: 20px;
}
input[type="number"] {
width: 80px;
padding: 10px;
margin: 10px 0;
border: 2px solid #007bff;
border-radius: 5px;
font-size: 16px;
}
button {
padding: 10px 20px;
background-color: #007bff;
border: none;
color: #ffffff;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s;
}
button:hover {
background-color: #0056b3;
}
.result-container {
margin-top: 20px;
}
#uid {
font-size: 18px;
color: #333333;
background-color: #f5f5f5;
padding: 10px;
border-radius: 5px;
border: 1px solid #dddddd;
}
.message {
margin-top: 10px;
color: #28a745;
font-weight: bold;
display: none;
}
JavaScript
function generateUID() {
const length = parseInt(document.getElementById('length').value);
if (isNaN(length) || length <= 0) return;
const digits = '23456789';
const letters = 'abcdefhkmnrstuvwxz'; // Excluding i,j,q,g,l,o,p,y
const numDigits = Math.floor(length / 3);
const numLetters = length - numDigits;
let uid = '';
for (let i = 0; i < numDigits; i++) {
uid += digits.charAt(Math.floor(Math.random() * digits.length));
}
for (let i = 0; i < numLetters; i++) {
uid += letters.charAt(Math.floor(Math.random() * letters.length));
}
// Shuffle the UID
uid = uid.split('').sort(() => Math.random() - 0.5).join('');
// Display the UID
const uidElement = document.getElementById('uid');
uidElement.textContent = uid;
// Copy to clipboard
navigator.clipboard.writeText(uid).then(() => {
const messageElement = document.getElementById('message');
messageElement.style.display = 'block';
setTimeout(() => {
messageElement.style.display = 'none';
}, 1000);
});
}