-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
60 lines (50 loc) · 1.78 KB
/
Copy pathscript.js
File metadata and controls
60 lines (50 loc) · 1.78 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
56
57
58
59
60
function generateDOIs(prefix, count) {
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const integers = "0123456789";
var outputDOIs = [];
for (let i = 0; i < count; i++) {
let letters = "";
let numbers = "";
for (let j = 0; j < 4; j++) {
letters += alphabet[Math.floor(Math.random() * alphabet.length)];
}
for (let j = 0; j < 4; j++) {
numbers += integers[Math.floor(Math.random() * integers.length)];
}
outputDOIs.push(`${prefix}/${letters}${numbers}`);
}
return outputDOIs;
}
document.addEventListener("DOMContentLoaded", (event) => {
document.getElementById("generate").addEventListener("click", () => {
const prefix = document.getElementById("prefix").value.trim();
const count = parseInt(document.getElementById("count").value);
const error = document.getElementById("error");
if (!prefix) {
error.textContent = "Please enter a prefix";
error.style.display = "block";
return;
}
if (!count || count < 1 || count > 1000) {
error.textContent = "Please enter a number between 1 and 1000";
error.style.display = "block";
return;
}
console.log(count);
const DOIs = generateDOIs(prefix, count);
document.getElementById("output").value = DOIs.join("\n");
document.getElementById("results").style.display = "block";
document.getElementById("copy-btn").addEventListener("click", () => {
const text = document.getElementById("output").value;
navigator.clipboard.writeText(text).then(() => {
const btn = document.getElementById("copy-btn");
btn.textContent = "Copied!";
btn.classList.add("copied");
setTimeout(() => {
btn.textContent = "Copy";
btn.classList.remove("copied");
}, 2000);
});
});
});
});