-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
55 lines (47 loc) · 1.68 KB
/
script.js
File metadata and controls
55 lines (47 loc) · 1.68 KB
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
document.getElementById("generate-btn").addEventListener("click", generateUUIDs);
document.getElementById("download-btn").addEventListener("click", downloadUUIDs);
async function generateUUIDs() {
const count = document.getElementById("uuid-count").value;
const version = document.getElementById("uuid-version").value;
const apiUrl = `https://www.uuidtools.com/api/generate/${version}/count/${count}`;
if (count < 1 || count > 100) {
alert("Please enter a number between 1 and 100.");
return;
}
try {
const response = await fetch(apiUrl);
if (!response.ok) throw new Error("Failed to fetch UUIDs.");
const uuids = await response.json();
displayUUIDs(uuids);
} catch (error) {
alert("Error generating UUIDs. Please try again.");
console.error(error);
}
}
function displayUUIDs(uuids) {
const listContainer = document.getElementById("uuid-list");
listContainer.innerHTML = "";
uuids.forEach(uuid => {
const div = document.createElement("div");
div.textContent = uuid;
listContainer.appendChild(div);
});
}
function downloadUUIDs() {
const listContainer = document.getElementById("uuid-list");
if (listContainer.children.length === 0) {
alert("No UUIDs to download. Generate some first.");
return;
}
let textContent = "";
listContainer.childNodes.forEach(node => {
textContent += node.textContent + "\n";
});
const blob = new Blob([textContent], {
type: "text/plain"
});
const link = document.createElement("a");
link.href = URL.createObjectURL(blob);
link.download = "uuids.txt";
link.click();
}