-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
68 lines (66 loc) · 2.42 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!DOCTYPE html>
<html>
<head>
<title>UID Generator</title>
</head>
<body>
<h1>UID Generator</h1>
<form>
<label for="num-uids">Number of UIDs to generate:</label>
<input type="number" id="num-uids" name="num-uids" min="1" max="1000" value="10">
<button type="button" onclick="generateUIDs()">Generate</button>
</form>
<div id="logs"></div>
<a id="download-link" style="display: none">Download UIDs</a>
<script>
function generateUIDs() {
// Get the number of UIDs to generate from the input field
const numUIDs = parseInt(document.getElementById("num-uids").value);
// Initialize an array to store the generated UIDs
const uids = [];
// Generate the specified number of UIDs
for (let i = 0; i < numUIDs; i++) {
uids.push(
generateUID()
);
}
// Log the generated UIDs
log(uids.join("\n"));
// Convert the UIDs to a Blob object and create a download link
const blob = new Blob([uids.join("\n")], { type: "text/plain" });
const downloadLink = document.getElementById("download-link");
downloadLink.href = URL.createObjectURL(blob);
downloadLink.download = "uids.txt";
// Show the download link
downloadLink.style.display = "block";
}
function generateUID() {
// Initialize an array of hexadecimal digits
const hexDigits = "0123456789abcdef".split("");
// Generate a random 32-bit integer
let num = new Uint32Array(1);
window.crypto.getRandomValues(num);
// Convert the integer to a string of hexadecimal digits
const hexArray = [];
for (let i = 0; i < 8; i++) {
hexArray.push(hexDigits[(num[0] >> (4 * i)) & 0xf]);
}
// Insert hyphens at the appropriate positions to create a UUIDv4 string
hexArray.splice(4, 0, "-");
hexArray.splice(7, 0, "-");
hexArray.splice(12, 0, "-");
hexArray.splice(17, 0, "-");
return hexArray.join("");
}
function log(message) {
// Get the logs element
const logs = document.getElementById("logs");
// Create a new log entry
const logEntry = document.createElement("p");
logEntry.textContent = message;
// Add the log entry to the logs element
logs.appendChild(logEntry);
}
</script>
</body>
</html>