-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
58 lines (52 loc) · 1.46 KB
/
Copy pathscripts.js
File metadata and controls
58 lines (52 loc) · 1.46 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
const lengthBox = document.getElementById("length");
const lowerAlphaCb = document.getElementById("lower");
const upperAlphaCb = document.getElementById("upper");
const numberCb = document.getElementById("number");
const symbolCb = document.getElementById("symbol");
const symbolList = document.getElementById("symbol-list");
const randStr = document.getElementById("rand-str");
function decreaseLength() {
if (lengthBox.value > 1) {
lengthBox.value--;
}
}
function increaseLength() {
lengthBox.value++;
return false;
}
function setLength(btnId) {
lengthBox.value = document.getElementById(btnId).innerText;
}
function generateStr() {
const length = lengthBox.value;
const symbols = symbolList.value;
const lowerStr = "abcdefghijklmnopqrstuvwxyz";
const upperStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const numStr = "0123456789";
let stringSrc = "";
if (lowerAlphaCb.checked) {
stringSrc += lowerStr;
}
if (upperAlphaCb.checked) {
stringSrc += upperStr;
}
if (numberCb.checked) {
stringSrc += numStr;
}
if (symbolCb.checked) {
stringSrc += symbols;
}
const randomArray = new Uint32Array(length);
const maxNum = 2 ** 32;
crypto.getRandomValues(randomArray);
let result = "";
for (let num of randomArray) {
const index = Math.floor(num / maxNum * stringSrc.length);
result += stringSrc.charAt(index);
}
randStr.value = result;
}
function copyStr() {
navigator.clipboard.writeText(randStr.value);
}
generateStr();